How to Read RegularEx and MaxLength valules from Validation Rules

How to Read RegularEx and MaxLength valules from Validation Rules

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


galford posted on Thursday, December 31, 2009


I want to use Regular expression and maximum length values within user interface to set editor properties. I could find a way to read this values in object.

How can I read validation rules collection? and How can I access to the regular ex and max length values within this collection?


Note: Since I don't have time, I'm adding public RegularExpressionCollection and MaxLenthCollection to my class and adding values to this collections while adding validation rules. And I will use this collections but I think this is not a good solution since this information is already available in validation rules which I couldn't find a way to read it.

rxelizondo replied on Friday, January 01, 2010


Not sure if this is what you are asking but one way that I know to get information about your business rules is to do something like this:

--------------------------------------------------

string[] ruleDescriptions = ValidationRules.GetRuleDescriptions();
foreach (string rds in ruleDescriptions)
{
Csla.Validation.RuleDescription rdo = new Csla.Validation.RuleDescription(rds);
foreach (var kvp in rdo.Arguments)
{
Console.WriteLine(kvp.Key + "=" + kvp.Value);
}
}

--------------------------------------------------

galford replied on Tuesday, January 05, 2010

rxelizondo:
Not sure if this is what you are asking but one way that I know to get information about your business rules is to do something like this:

--------------------------------------------------

string[] ruleDescriptions = ValidationRules.GetRuleDescriptions();
foreach (string rds in ruleDescriptions)
{
Csla.Validation.RuleDescription rdo = new Csla.Validation.RuleDescription(rds);
foreach (var kvp in rdo.Arguments)
{
Console.WriteLine(kvp.Key + "=" + kvp.Value);
}
}

--------------------------------------------------


This code just work fine, and I could use validation rules to set editor properties. Thank you very much.




Marjon1 replied on Saturday, January 02, 2010

I've got an example of how to do this with a user control, similar to the Authorization Control that comes with CSLA. I'm not at work at moment but will post it within the next 24 hours. You give it a binding source and it does the rest for you.

You could then adjust it to work with your specific controls in needed. It has been a great way to limit mistakes in the UI.

Marjon

Marjon1 replied on Sunday, January 03, 2010

Please find attached the VB project that has the extender provider to automatically set the MaxLength property on any Textbox that is bound to a property that has the StringLengthAttribute.

Hopefully you find this useful, the original was specifically tied to our DevExpress controls and had additional code to set their MaxLength properties as well, so can be modified to meet your controls.

galford replied on Monday, January 04, 2010

Thanks for help. I will work on it.
I'm also using devexpress controls, I'm gonna convert your code to C# first,
then modify it for devexpress controls.

Copyright (c) Marimer LLC