AddDependantProperty doesn't appear to work on Instance Rules.AddDependantProperty doesn't appear to work on Instance Rules.
Old forum URL: forums.lhotka.net/forums/t/1375.aspx
tpancoast posted on Tuesday, October 03, 2006
FYI: The new AddDependantProperty doesn't appear to work when you have a combination of Instance and Type (ie static) Rules. In my first pass at converting my objects to 2.1, I was being lazy and just changed it to use AddInstanceRule, since my rules were not static. I was also using some CommonRules, so this created a mix of Instance and Type rules. When ValidationRules.CheckRules(string propertyName) goes to check the dependencies (GetDependancyList(false), it returns a null dependency list.
I think the problem is that ValidationRulesManager.RulesToCheck consolidates the Instance and Type rules into a new list, but it doesn't create a consolidated dependency list.
This just convinced me to do the right thing and convert my rules to static, so I didn't actually verify that this would fix it.
P.S. Sorry if this is the wrong way to report this.
RockfordLhotka replied on Tuesday, October 03, 2006
This does appear to be a bug - thanks for pointing it out.
RockfordLhotka replied on Wednesday, October 04, 2006
I have changed ValidationRules to merge the dependancy list along with the rules, which should fix this issue.
Can you do me a favor and test the change in your setting? If you to to www.lhotka.net/cslacvs you can go get the updated ValidationRules source file and replace your current file with this one.
Thanks!
tpancoast replied on Wednesday, October 04, 2006
Not every RuleList has a Dependancy List, so the current change gets NullReferenceExceptions. In RulesToCheck, Change:
rules.GetDependancyList(false).AddRange(de.Value.GetDependancyList(false));
to:
if (de.Value.GetDependancyList(false) != null)
rules.GetDependancyList(true).AddRange(de.Value.GetDependancyList(false));
RockfordLhotka replied on Wednesday, October 04, 2006
OK, try the current code - I think that should do it.tpancoast replied on Wednesday, October 04, 2006
Still gets a NullReferenceException. Try this instead:
List<string> dependancy = de.Value.GetDependancyList(false);
if (dependancy != null)
rules.GetDependancyList(true).AddRange(dependancy);
RockfordLhotka replied on Wednesday, October 04, 2006
Ahh, I should have seen that... I'm running from one thing to the next today, and I should just hold off making changes until I can sit down and do it right...
In any case, I put the change into cvs.
tpancoast replied on Wednesday, October 04, 2006
O.K. Works now. Thanks.SimonL replied on Thursday, November 16, 2006
Is this in a version that is downloadable. We're using 2.1 and need this feature. If its in the cvs where do I find the cvs.
Regards,
Simon
RockfordLhotka replied on Thursday, November 16, 2006
Dependant properties apply to both per-type and
per-instance rules. It is important to realize that once the object has been
instantiated in memory, its per-type and per-instance rule lists are merged into
a single list, sorted by priority. This is required to make short-circuiting
work.
As such, the concept of dependant properties is really
independent from per-type or per-instance.
So you set the dependencies in AddBusinessRules(), and they
apply to all rules, per-type and per-instance.
Rocky
Is this in a version that is downloadable. We're using 2.1 and need this
feature. If its in the cvs where do I find the cvs.
Regards,
Simon
Copyright (c) Marimer LLC