Using RegisterProperty(Expression) in base class errors out for VB.

Using RegisterProperty(Expression) in base class errors out for VB.

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


Killian35 posted on Monday, May 11, 2009

Hello,

There seems to be a difference between the way VB and C# deal with creating an expression. I'm working on both C# and VB projects and I'm upgrading the VB project to Csla 3.6.2. I really love the expression declaration used in the RegisterProperty method, so I was changing those over and found that in VB using that approach generates a run-time error if the RegisterProperty is declared in a base class. Here is an example that reproduces the error for VB. The exact same C# version runs as expected.

Module Module1

    Sub Main()
        Dim p As Person = Person.NewPerson
        Debug.WriteLine(p.Age)
    End Sub

End Module

<Serializable()> _
Public MustInherit Class BaseClass(Of T As BaseClass(Of T))
    Inherits BusinessBase(Of T)

    Protected Sub New()
    End Sub

    Private Shared AgeProperty As PropertyInfo(Of Integer) = RegisterProperty(Of Integer)(Function(c) c.Age)
    Public Property Age() As Integer
        Get
            Return GetProperty(AgeProperty)
        End Get
        Set(ByVal value As Integer)
            SetProperty(AgeProperty, value)
        End Set
    End Property

    Protected Overrides Sub DataPortal_OnDataPortalInvokeComplete(ByVal e As Csla.DataPortalEventArgs)
        If e.Operation = DataPortalOperations.Create Then
            Me.Age = 5
        End If
    End Sub
End Class

<Serializable()> _
Public Class Person
    Inherits BaseClass(Of Person)

    Private Sub New()
    End Sub

    Public Shared Function NewPerson() As Person
        Return DataPortal.Create(Of Person)()
    End Function

End Class

Is there a difference in how VB handles lambda expressions from C#?

Thank you for any help!
Kelly

Copyright (c) Marimer LLC