Using Lambda Expressions in Csla.Net property registration

March 4, 2009 13:23 by ndibek

With Csla.Net 3.5 came a concept of "managed properties", properties that automatically handle business and authorization rules, without additional code reguired to wire up all those notifications.  In 3.6 managed properties were extended to allow serializing Csla.Net objects accross different runtimes (.Net to Silverlght).

The thing I do not like about property registration was, while it resembled dependency properties from WP/Silverlight, it required string constants or property names.  And string constants as we know are BAAD! 

So, in 3.6.2 we are adding another way to register properties - using Linq Expression API!  Lets take a look at the example:

    private static PropertyInfo DescriptionProperty = 
      RegisterProperty(p=>p.Description);
    public string Description
    {
      get { return GetProperty(DescriptionProperty); }
      set { SetProperty(DescriptionProperty, value); }
    }

Besides being shorter, this syntax supports full Intellisense, as the only expressions allowed are Property expressions of properties belonging to the object. This is compile time safe.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading