Subclassed PropertyInfo, Custom PropertyInfoFactory, and RegisterProperty using Lambda

Subclassed PropertyInfo, Custom PropertyInfoFactory, and RegisterProperty using Lambda

Old forum URL:

comp1mp posted on Wednesday, October 26, 2011


I have implemented  MyPropertyInfo<T> derived from PropertyInfo<T> and a custom PropertyInfoFactory which returns my derived type.

My BO declaration however uses the lambda RegisterProperty overload and is declared as PropertyInfo<T>, not my subclassed type

private static PropertyInfo<T> LastNameProperty = RegisterProperty<T>(c => c.Property);

This is consistent with the suggestion of Jonny Bekkum in the following post

I have run across a few older posts by Rocky about extending PropertyInfo<T> without using a custom PropertyInfoFactory (??? not sure if Rocky is just omitting the need for the factory)

Here is his sample declaration

private static MyPropertyInfo<string> =
  RegisterProperty(new MyPropertyInfo<string>(...));

He uses an older overload for register property, but notice that he is declaring his derived type instead of PropertyInfo<T>.

Two questions:

1. Even though my current implementation 'works', is there a compelling reason to declare using my derived class instead of the base PropertyInfo<T>?

I can do this but have to cast:

private static MyPropertyInfo<T> LastNameProperty = (MyPropertyInfo<T>)RegisterProperty<T>(c => c.Property);

2. I have the following key in my app.config, but when the first property attempts to initialize the Factory is null. Do I need more info in the value attribute? 

add key="CslaPropertyInfoFactory" value="OrionCsla.PropertyInfoFactory"



JonnyBee replied on Wednesday, October 26, 2011

1. You only need to do this if you need direct access to the added properties in PropertyInfo.
     Else your code will only see the base properties from PropertyInfo base class.

2. Yes, when the first call to RegisterProperty is called your will hit

Csla.Core.FieldManager.PropertyInfoFactory.Factory which will check the CslaPropertyInfoFactory 
and create a common instance of that object

comp1mp replied on Wednesday, October 26, 2011

I also implemented an interface IMyPropertyInfo which exposes all of the properties in MyPropertyInfo<T>. This should allow me to acces the extended properties if necessary from the base PropertyInfo<T>.

Copyright (c) Marimer LLC