示例#1
0
        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;
        }
示例#2
0
 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());
 }
示例#3
0
 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));
 }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        //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);
        }
示例#7
0
        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));
        }
示例#10
0
 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());
 }
示例#11
0
 public static M CallValidate <M, T, R>(this IMustPassRule <M, T, R> mpr) where M : ISetupClass
 {
     return(CallValidate(mpr, mpr.RulesRulesEngine));
 }
示例#12
0
 public static M MustPassGenericRule <M, T, R>(this IMustPassRule <M, T, R> mpr, Func <R, bool> rule)
 {
     return(mpr.MustPassRule(new GenericRule <R>(rule)));
 }
示例#13
0
 public static M MustBeOfType <M, T, R>(this IMustPassRule <M, T, R> mpr, Type type)
 {
     return(mpr.MustPassRule(new OfTypeRule <R>(type)));
 }
示例#14
0
 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))));
 }
示例#15
0
 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)));
 }
示例#16
0
 public static M MustBeNull <M, T, R>(this IMustPassRule <M, T, R> mpr)
     where R : class
 {
     return(mpr.MustPassRule(new NullRule <R>()));
 }
示例#17
0
 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)));
 }
示例#18
0
 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)));
 }
示例#19
0
 public static M MustNotBeOneOf <M, T, R>(this IMustPassRule <M, T, R> mpr, params R[] values)
 {
     return(mpr.MustPassRule(new NotOneOfRule <R>(values)));
 }
示例#20
0
 public static M MustNotBeOneOf <M, T, R>(this IMustPassRule <M, T, R> mpr, IEnumerable <R> values)
 {
     return(mpr.MustPassRule(new NotOneOfRule <R>(values)));
 }
示例#21
0
 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)));
 }
示例#22
0
 public static M CallValidateForEachElement <M, T, R>(this IMustPassRule <M, T, R> mpr)
     where R : IEnumerable
     where M : ISetupClass
 {
     return(CallValidateForEachElement(mpr, mpr.RulesRulesEngine));
 }
示例#23
0
 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)));
 }
示例#24
0
 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)));
 }
示例#25
0
 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)));
 }
示例#26
0
 public static M MustNotEqual <M, T, R>(this IMustPassRule <M, T, R> mpr, R value)
 {
     return(mpr.MustPassRule(new NotEqualRule <R>(value)));
 }
示例#27
0
 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)));
 }
示例#28
0
 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)));
 }
示例#29
0
 public static M MustNotBeNullOrEmpty <M, T>(this IMustPassRule <M, T, string> mpr)
 {
     return(mpr.MustPassRule(new NotNullOrEmpty()));
 }
示例#30
0
 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)));
 }