public static M WithMessage <M, T, R>(this IMustPassRule <M, T, R> mpr, Func <string> message) { if (message == null) { throw new System.ArgumentNullException("message"); } var fluentNode = AsNode(mpr); var tmpScope = fluentNode.FluentScope.CreateChild(); tmpScope.Set(RegistryKeys.Message, message); tmpScope.Set(RegistryKeys.FluentScopeAction, new FluentScopeAction(BuilderHelper.RegisterMessage)); return((M)fluentNode.GetSelf(tmpScope)); ////TODO: This is not the best. Should I be assuming that the properties will have children here. ////This is because the Setup entry adds a scope for each new rule. ////Here I am interested in the scope for the rule, not the Setup one. //if (mpr.Properties.Children.Any()) //{ // var fluentScope = mpr.Properties.Children.Last(); // var messageEntry = new MessageEntry(typeof(T), new EquatableExpression(mpr.Expression), fluentScope.Get(RegistryKeys.Rule, null), message); // mpr.Properties.Children.Last().Set(RegistryKeys.MessageEntry, messageEntry); //} //else //{ // var messageEntry = new MessageEntry(typeof(T), new EquatableExpression(mpr.Expression), null, message); // mpr.Properties.Set(RegistryKeys.MessageEntry, messageEntry); //} //return (M)mpr; }
public static M CallValidateForEachElement <M, T, R>(this IMustPassRule <M, T, R> mpr, RulesEngine usingRulesEngine) where R : IEnumerable where M : ISetupClass { mpr.RulesRulesEngine.RegisterEnumerableComposition(mpr.Expression, usingRulesEngine); return(mpr.GetSelf()); }
public static M WithMessage <M, T, R>(this IMustPassRule <M, T, R> mpr, string message) { if (message == null) { throw new System.ArgumentNullException("message"); } return(WithMessage(mpr, () => message)); }
public static M MustBeBetween <M, T, R>(this IMustPassRule <M, T, R> mpr, R greaterThan, R lessThan, BetweenRuleBoundsOption bounds) where R : IComparable <R> { Expression <Func <T, R> > greaterThanFunc = f => greaterThan; Expression <Func <T, R> > lessThanFunc = f => lessThan; return(MustBeBetween(mpr, greaterThanFunc, lessThanFunc, bounds)); }
public static M MustBeBetween <M, T, R>(this IMustPassRule <M, T, R> mpr, Expression <Func <T, R> > greaterThan, Expression <Func <T, R> > lessThan) where R : IComparable <R> { BetweenRuleBoundsOption bounds = DefaultBoundOption; Expression <Func <T, R> > greaterThanFunc = greaterThan; Expression <Func <T, R> > lessThanFunc = lessThan; return(MustBeBetween(mpr, greaterThanFunc, lessThanFunc, bounds)); }
//TODO: This is repeated code (from RulesHelper, make it reuseable). private static IFluentNode AsNode <M, T, R>(IMustPassRule <M, T, R> mpr) { var result = mpr as IFluentNode; if (result == null) { throw new InvalidOperationException("IMustPassRule is not a valid node."); } return(result); }
public static M WithMessage <M, T, R>(this IMustPassRule <M, T, R> mpr, Func <string> message) { if (message == null) { throw new System.ArgumentNullException("message"); } //NOTE: Use the rulesEngine must be the original - i.e. Setting Messages on nested If's RulesEngine. var rulesEngine = mpr.RulesEngine.Original; rulesEngine.DefaultErrorResolver.SetErrorMessageFor(typeof(T), new EquatableExpression(mpr.Expression), mpr.LastRule, message); return(mpr.GetSelf()); }
public static M CallValidate <M, T, R>(this IMustPassRule <M, T, R> mpr, IEngine usingEngine) where M : ISetupClass { var tmpScope = mpr.FluentScope.CreateChild(); tmpScope.Set(RegistryKeys.FluentScopeAction, new FluentScopeAction(BuilderHelper.RegisterComposition)); tmpScope.Delete(RegistryKeys.Rule); if (usingEngine != null) { tmpScope.Set(RegistryKeys.UsingEngine, usingEngine); } else { tmpScope.Delete(RegistryKeys.UsingEngine); } return((M)mpr.GetSelf(tmpScope)); }
public static M CallValidateForEachElement <M, T, R>(this IMustPassRule <M, T, R> mpr, IEngine usingEngine) where R : IEnumerable where M : ISetupClass { //TODO: Create a test for testing what happens when you have nodes after the CallValidateForEachElement... var tmpScope = mpr.FluentScope.CreateChild(); tmpScope.Set(RegistryKeys.FluentScopeAction, new FluentScopeAction(BuilderHelper.RegisterEnumerableComposition)); tmpScope.Delete(RegistryKeys.Rule); if (usingEngine != null) { tmpScope.Set(RegistryKeys.UsingEngine, usingEngine); } else { tmpScope.Delete(RegistryKeys.UsingEngine); } return((M)mpr.GetSelf(tmpScope)); }
public static M CallValidate <M, T, R>(this IMustPassRule <M, T, R> mpr, RulesEngine usingRulesEngine) where M : ISetupClass { usingRulesEngine.RegisterComposition(mpr.Expression, usingRulesEngine); return(mpr.GetSelf()); }
public static M CallValidate <M, T, R>(this IMustPassRule <M, T, R> mpr) where M : ISetupClass { return(CallValidate(mpr, mpr.RulesRulesEngine)); }
public static M MustPassGenericRule <M, T, R>(this IMustPassRule <M, T, R> mpr, Func <R, bool> rule) { return(mpr.MustPassRule(new GenericRule <R>(rule))); }
public static M MustBeOfType <M, T, R>(this IMustPassRule <M, T, R> mpr, Type type) { return(mpr.MustPassRule(new OfTypeRule <R>(type))); }
public static M MustMatchRegex <M, T>(this IMustPassRule <M, T, string> mpr, string pattern, RegexOptions options) { return(mpr.MustPassRule(new RegexRule(new Regex(pattern, options)))); }
public static M MustNotEqual <M, T, R>(this IMustPassRule <M, T, R> mpr, Expression <Func <T, R> > value, IEqualityComparer <R> comparer) { return(mpr.MustPassRule(new NotEqualRule <T, R>(mpr.Expression, value, comparer))); }
public static M MustBeNull <M, T, R>(this IMustPassRule <M, T, R> mpr) where R : class { return(mpr.MustPassRule(new NullRule <R>())); }
public static M MustBeGreaterThanOrEqualTo <M, T, R>(this IMustPassRule <M, T, R> mpr, R greaterThan) where R : IComparable <R> { return(mpr.MustPassRule(new GreaterThanRule <R>(greaterThan, true))); }
public static M MustBeLessThan <M, T, R>(this IMustPassRule <M, T, R> mpr, Expression <Func <T, R> > lessThan) where R : IComparable <R> { return(mpr.MustPassRule(new LessThanRule <T, R>(mpr.Expression, lessThan, false))); }
public static M MustNotBeOneOf <M, T, R>(this IMustPassRule <M, T, R> mpr, params R[] values) { return(mpr.MustPassRule(new NotOneOfRule <R>(values))); }
public static M MustNotBeOneOf <M, T, R>(this IMustPassRule <M, T, R> mpr, IEnumerable <R> values) { return(mpr.MustPassRule(new NotOneOfRule <R>(values))); }
public static M MustBeOneOf <M, T, R>(this IMustPassRule <M, T, R> mpr, IEnumerable <R> values, IEqualityComparer <R> comparer) { return(mpr.MustPassRule(new OneOfRule <R>(values, comparer))); }
public static M CallValidateForEachElement <M, T, R>(this IMustPassRule <M, T, R> mpr) where R : IEnumerable where M : ISetupClass { return(CallValidateForEachElement(mpr, mpr.RulesRulesEngine)); }
public static M MustNotBeOneOf <M, T, R>(this IMustPassRule <M, T, R> mpr, IEqualityComparer <R> comparer, params R[] values) { return(mpr.MustPassRule(new NotOneOfRule <R>(values, comparer))); }
public static M MustBeBetween <M, T, R>(this IMustPassRule <M, T, R> mpr, Expression <Func <T, R> > greaterThan, Expression <Func <T, R> > lessThan, BetweenRuleBoundsOption bounds) where R : IComparable <R> { return(mpr.MustPassRule(new BetweenRule <T, R>(mpr.Expression, greaterThan, lessThan, bounds))); }
public static M MustBeLessThanOrEqualTo <M, T, R>(this IMustPassRule <M, T, R> mpr, R lessThan) where R : IComparable <R> { return(mpr.MustPassRule(new LessThanRule <R>(lessThan, true))); }
public static M MustNotEqual <M, T, R>(this IMustPassRule <M, T, R> mpr, R value) { return(mpr.MustPassRule(new NotEqualRule <R>(value))); }
public static M MustBeGreaterThanOrEqualTo <M, T, R>(this IMustPassRule <M, T, R> mpr, Expression <Func <T, R> > greaterThan) where R : IComparable <R> { return(mpr.MustPassRule(new GreaterThanRule <T, R>(mpr.Expression, greaterThan, true))); }
public static M MustNotEqual <M, T, R>(this IMustPassRule <M, T, R> mpr, R value, IEqualityComparer <R> comparer) { return(mpr.MustPassRule(new NotEqualRule <R>(value, comparer))); }
public static M MustNotBeNullOrEmpty <M, T>(this IMustPassRule <M, T, string> mpr) { return(mpr.MustPassRule(new NotNullOrEmpty())); }
public static M MustNotEqual <M, T, R>(this IMustPassRule <M, T, R> mpr, Expression <Func <T, R> > value) { return(mpr.MustPassRule(new NotEqualRule <T, R>(mpr.Expression, value))); }