How to check if a property is required in CSLA 4?

How to check if a property is required in CSLA 4?

Old forum URL:

Gort posted on Monday, October 25, 2010

I am doing a WPF app using CSLA 4.  Is there a way I can bind to the validation rules like whether a property is required, for example?

I'd like to have/know this information in my view model where I am using my biz object.


RockfordLhotka replied on Monday, October 25, 2010

CSLA objects expose information about validation rules in a couple ways.

IDataErrorInfo is the Microsoft-defined interface used by data binding to get validation information, and this is what WPF uses. Your viewmodel code can cast the business object to IDataErrorInfo and do the same thing as WPF.

However, CSLA's validation model is richer than Microsoft supports. If you want the full set of information, use the BrokenRulesCollection property, available directly on the business object itself. You can use LINQ queries to filter/sort that list to get at all the rich validation information for each object.

JonnyBee replied on Tuesday, October 26, 2010

If you want to get the rules URI's  then you can:

use <bo>.BusinessRules.GetRuleDescriptions() which will return the rule://URI decriptions for the registered business rules.

The registered rules are not directly exposed so you should use the rule URI's.

Copyright (c) Marimer LLC