17 public static class BusinessRulesExtensions
28 public static void AddRule<T>(
this BusinessRules businessRules,
Csla.
Core.
IPropertyInfo primaryProperty, Func<T, bool> ruleHandler,
string message,
RuleSeverity severity)
31 var rule =
new CommonRules.Lambda(primaryProperty, (o) =>
33 var target = (T) o.Target;
34 using (target.BypassPropertyChecks)
36 if (!ruleHandler.Invoke(target))
38 o.Results.Add(
new RuleResult(o.Rule.RuleName, primaryProperty,
string.Format(message, o.Rule.PrimaryProperty.FriendlyName)) {Severity = severity});
42 var methodName = ruleHandler.Method.ToString();
43 rule.AddQueryParameter(
"s", Convert.ToBase64String(Encoding.Unicode.GetBytes(methodName)));
45 businessRules.AddRule(rule);
56 public static void AddRule<T>(
this BusinessRules businessRules,
Csla.
Core.
IPropertyInfo primaryProperty, Func<T, bool> ruleHandler,
string message) where T :
BusinessBase
58 AddRule(businessRules, primaryProperty, ruleHandler, message,
RuleSeverity.Error);
71 public static void AddRule<T>(
this BusinessRules businessRules,
string ruleSet,
Csla.
Core.
IPropertyInfo primaryProperty, Func<T, bool> ruleHandler,
string message,
RuleSeverity severity)
74 var rule =
new CommonRules.Lambda(primaryProperty, (o) =>
76 var target = (T)o.Target;
77 using (target.BypassPropertyChecks)
79 if (!ruleHandler.Invoke(target))
81 o.Results.Add(
new RuleResult(o.Rule.RuleName, primaryProperty,
string.Format(message, o.Rule.PrimaryProperty.FriendlyName)) { Severity = severity });
85 var methodName = ruleHandler.Method.ToString();
86 rule.AddQueryParameter(
"s", Convert.ToBase64String(Encoding.Unicode.GetBytes(methodName)));
87 businessRules.AddRule(rule, ruleSet);
99 public static void AddRule<T>(
this BusinessRules businessRules,
string ruleSet,
Csla.
Core.
IPropertyInfo primaryProperty, Func<T, bool> ruleHandler,
string message) where T :
BusinessBase
101 AddRule(businessRules, primaryProperty, ruleHandler, message,
RuleSeverity.Error);
113 public static void AddRule<T>(
this BusinessRules businessRules,
Csla.
Core.
IPropertyInfo primaryProperty, Func<T, bool> ruleHandler, Func<string> messageDelegate,
RuleSeverity severity)
116 AddRule(businessRules, ApplicationContext.DefaultRuleSet, primaryProperty, ruleHandler, messageDelegate, severity);
128 public static void AddRule<T>(
this BusinessRules businessRules,
Csla.
Core.
IPropertyInfo primaryProperty, Func<T, bool> ruleHandler, Func<string> messageDelegate) where T :
BusinessBase
130 AddRule(businessRules, ApplicationContext.DefaultRuleSet, primaryProperty, ruleHandler, messageDelegate,
RuleSeverity.Error);
143 public static void AddRule<T>(
this BusinessRules businessRules,
string ruleSet,
Csla.
Core.
IPropertyInfo primaryProperty, Func<T, bool> ruleHandler, Func<string> messageDelegate,
RuleSeverity severity)
146 var rule =
new CommonRules.Lambda(primaryProperty, (o) =>
148 var target = (T)o.Target;
149 using (target.BypassPropertyChecks)
151 if (!ruleHandler.Invoke(target))
153 o.Results.Add(
new RuleResult(o.Rule.RuleName, primaryProperty, messageDelegate.Invoke()) { Severity = severity });
157 var methodName = ruleHandler.Method.ToString();
158 rule.AddQueryParameter(
"s", Convert.ToBase64String(Encoding.Unicode.GetBytes(methodName)));
159 businessRules.AddRule(rule, ruleSet);
171 public static void AddRule<T>(
this BusinessRules businessRules,
string ruleSet,
Csla.
Core.
IPropertyInfo primaryProperty, Func<T, bool> ruleHandler, Func<string> messageDelegate) where T :
BusinessBase
173 AddRule(businessRules, ruleSet, primaryProperty, ruleHandler, messageDelegate,
RuleSeverity.Error);
This is the non-generic base class from which most business objects will be derived.
Maintains metadata about a property.
RuleSeverity
Values for validation rule severities.