during conversion of a CSLA.NET 1.x project into CSLA.NET 3.0 we got some strange behavior due to not fully understanding the ValidationRule implementation.
This has now been fixed but left a question regarding the requirements of static methods for shared (per-type) ValidationRules.
Within the Validation.ValidationRules class there is a method called ValidateHandler that is used to validate the given BusinessRule handler method before it is added for the object type.
The validation consists of a conditional statement where the given method must be static if declared by the target class. The specific code looks like the following:
if (!method.IsStatic && method.DeclaringType.Equals(_target.GetType()))
I am not sure I fully understand the purpose of the second condition but should/could it not be expressed as
if (!method.IsStatic && method.DeclaringType.IsInstanceOfType(_target))
I.e. why is it only required of a method to be static if it is declared in the target class and not if it is declared in any of the classes that the target class is derived from?
Interesting, this is a valid concern. I'll add this to the wish list.
Copyright (c) Marimer LLC