Managed Backing Fields with Type Conversion: I can't use the method GetPropertyConvert in the CSLA 3.5 using VS2008

Managed Backing Fields with Type Conversion: I can't use the method GetPropertyConvert in the CSLA 3.5 using VS2008

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


tutus posted on Thursday, September 24, 2009

I try to use this code for one my buisness object properties:

        Private Shared NBR_DOORSProperty As PropertyInfo(Of Nullable(Of Integer)) = RegisterProperty(GetType(Nullable(Of Integer)), New PropertyInfo(Of Nullable(Of Integer))("NBR_DOORS"))
        Public Property NBR_DOORS() As Nullable(Of Integer)
            Get
                Return GetPropertyConvert((NBR_DOORSProperty)
            End Get
            Set(ByVal Value As Nullable(Of Integer))
                SetPropertyConvert(NBR_DOORSProperty, Nothing)
            End Set
        End Property
But I get the error that GetPropertyConvert does not exisit or something like that !!!
Is that normal ?
The reason why I m using GetPropertyConvert is that my property is of type Nullable(Of Integer). 
Just to let u know, When I tried to use the regular method: GetProperty, SetProperty I got the run time error : 
Index is out of range or something like that; 
it seemed like the framework did not allow the creation of GetProperty/SetProperty for type: 
nullable(Of Integer).
Therefore, I m trying to use GetPropertyConvert instead (pls correct me If I'm wrong )
I m using version 3.5 of CSLA and VS2008.
Thanks a lot for your time

Tom_W replied on Thursday, September 24, 2009

I'm not sure about 3.5, but certainly in 3.6.x you shouldn't need to a convert to use a nullable type for a property, this code is from our production system (3.6.3) and works fine:
private static PropertyInfo<int?> AccountNoProperty = RegisterProperty(new PropertyInfo<int?>("AccountNo", "Account No"));
If you can cut and paste the exact error messages that may help someone who knows 3.5 well track down the issue.

Tom_W replied on Thursday, September 24, 2009

Should your private property declaration read:
        Private Shared NBR_DOORSProperty As PropertyInfo(Of Nullable(Of Integer)) = RegisterProperty(New PropertyInfo(Of Nullable(Of Integer))("NBR_DOORS"))
(I removed the GetType(Nullable(Of Integer)),  part of the code)

ajj3085 replied on Thursday, September 24, 2009

Don't use the overload of RegisterProperty that takes Type as its first argument.

The Type argument tell Csla to what .Net type the proeprty is registered, and you're saying it belongs to Int32, when it should belong to your BO.

Perhaps Rocky should add that attributre which hides those overloads from Intellisense..

Copyright (c) Marimer LLC