On Dynamic properties, instance rules and property info requirements

On Dynamic properties, instance rules and property info requirements

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


xal posted on Thursday, June 16, 2011

I have an interesting scenario that worked like a charm in older versions and I'm looking at migration possibilities.

An application has a fixed set of fields for a -let's say- person, but allows the user to define custom fields that will be displayed in another tab.

Back then I wrote a CustomProperties class with a custom property descriptor that did read/writes by calling custom GetProperty and SetProperty methods in the CustomProperties object. Those methods would work against a hashtable contained by that same object.

I used Instance Rules for validation, since the available properties could change at runtime.

It all worked very well with databinding and even IDataErrorInfo support provided by Csla itself.

I obviously can't have static PropertyInfo objects for those properties, because they are dynamic, and at the same time I'm unable to create rules for those properties for that same reason.

I don't see a way of porting this code to the latest version of csla with the new property/rules system. Any ideas?

 

Andrés

JonnyBee replied on Thursday, June 16, 2011

Yes, instance rules are gone.

1. If you could supply some more metadata fro your property (for validation) you could create a gateway rule that in turn could call any rule based on the metadata.

2. Gateway rules may also be used to trigger an external rule engine (or your code) that returns a set of IPropertyInfo, level and message to be set into RuleContext (and then into your BO bu the rule engine).

You would probable have to create a list of "CustomProperties". I haven't made this type of dynamic properties so I have no personal experience into this challenge. I hope others on the forum will join in on the discussion.

 

 

xal replied on Thursday, June 16, 2011

I have the rules for each property stored in the database. Mostly basic stuff like required, or min/max length.

The problem is I still need to have a PropertyInfo object for each of them, and since they are dynamic, it wouldn't work.

The implementation I use today uses a hashtable in the business object and a custom property descriptor that fills the gap between databinding and the business object. It works very well with data forms and data grids.

I can't imagine right now how to make it work since I can't run validation without property info objects, which I can't define at runtime.

Why were instance rules removed? AFAIK they didn't have any penalty unless you actually decided to use them.

 

Andrés

Copyright (c) Marimer LLC