[Csla 3.6.x] GetPropertyConvert(F,P)

[Csla 3.6.x] GetPropertyConvert(F,P)

Old forum URL: forums.lhotka.net/forums/t/5474.aspx


stefan posted on Friday, September 26, 2008

Hi Rocky!

Consider the folling:
    Private Shared MyInfoProperty As PropertyInfo(Of MyReadOnlyInfo) _
            = RegisterProperty(GetType(MyBO), _
                    New PropertyInfo(Of
MyReadOnlyInfo)("MyInfo", "MyInfo", MyReadOnlyInfo.EmptyInfo))
    Private m
MyReadOnlyInfo As MyReadOnlyInfo = MyInfoProperty.DefaultValue
    Public ReadOnly Property MyInfo() As String
        Get
          Return GetPropertyConvert(Of
MyReadOnlyInfo, String)(MyInfoProperty, mMyReadOnlyInfo)
        End Get
    End Property

I would expect that the framework returns the result of the ToString() method on MyReadOnlyInfo,
but it does not.
Another alternative would be a new overload passing in the desired result:
GetPropertyConvert(F,P)(propInfo As PropertyInfo(Of F), returnValue As P)

But in the case of P being String, calling ToString() should be the expected behaviour...

Stefan

RockfordLhotka replied on Friday, September 26, 2008

So what you are suggesting is that Utilities.CoerceValue() should have a special case to handle a target type of string that just calls ToString() in the inbound value rather than trying to do the type coercion?

That may not be a bad idea, as it would probably provide better performance in many cases.

Copyright (c) Marimer LLC