Simplify Properties so no need for 'RegisterProperty' calls.

Simplify Properties so no need for 'RegisterProperty' calls.

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


boo posted on Thursday, June 11, 2009

So pasting code on this forum is not supported it seems.   Attached is an example of a way I think properties could be even simpler.

The idea is that this would be down in the base class doing all the hard work.

The example is rough, but it could probably be tweaked to be a little more type safe.   The point is the concept, not the implementation.   I 'borrowed' some code from Csla core to keep things type safe in my example.

RockfordLhotka replied on Friday, June 12, 2009

The one drawback I see to this, is that the static fields, when public, are terribly useful when creating an object factory. Without those static tokens, the object factory has no way to call LoadProperty() or ReadProperty(), and that's often quite important.

I'm also not entirely sure the concept will work in Silverlight, due to the limitations on reflection.

The primary reason for inventing this whole property syntax (and managed backing fields) was to support Silverlight, so if the technique doesn't work there then it is (to my mind) not useful.

Copyright (c) Marimer LLC