コード例 #1
0
ファイル: RuleExtensions.cs プロジェクト: mac-michael/bfsharp
        public static TRule WithCondition <TRule, TOwner>(this IRuleOwner <TRule, TOwner> rule,
                                                          Func <TOwner, bool> condition)
            where TRule : Rule
        {
            var r = (TRule)rule;

            r.Condition = x => condition((TOwner)x);

            return(r);
        }
コード例 #2
0
ファイル: RuleExtensions.cs プロジェクト: mac-michael/bfsharp
        public static TRule WithOwner <TRule, TOwner>(this IRuleOwner <TRule, TOwner> rule,
                                                      Expression <Func <TOwner, object> > propertySelector)
            where TRule : ValidationRuleBase
        {
            var r = (TRule)rule;

            var path         = DependencyHelper.GetPropertyPath(propertySelector).ToArray();
            var propertyPath = string.Join(".", path);

            r.Owner = propertyPath;

            return(r);
        }
コード例 #3
0
ファイル: RuleExtensions.cs プロジェクト: mac-michael/bfsharp
        public static TRule WithDependencies <TRule, TOwner, TType>(this IRuleOwner <TRule, TOwner> rule,
                                                                    params Expression <Func <TOwner, TType> >[] propertySelectors)
            where TRule : Rule
        {
            var r = (TRule)rule;

            foreach (var selector in propertySelectors)
            {
                var propertyPath = DependencyHelper.GetPropertyPath(selector);

                r.AddPropertyDependency(propertyPath.ToList());
            }

            return(r);
        }
コード例 #4
0
ファイル: RuleExtensions.cs プロジェクト: mac-michael/bfsharp
        public static TRule WithCollectionDependencies <TRule, TOwner, TItem>(
            this IRuleOwner <TRule, TOwner> rule,
            Expression <Func <TOwner, IEnumerable <TItem> > > collectionSelector,
            params Expression <Func <TItem, object> >[] propertySelectors)
            where TRule : Rule
        {
            var r          = (TRule)rule;
            var enumerable = DependencyHelper.GetPropertyPath(collectionSelector);
            var p          = new PropertyPath(enumerable);

            foreach (var selector in propertySelectors)
            {
                var propertyPath = new PropertyPath(DependencyHelper.GetPropertyPath(selector));
                r.AddPropertyDependency(p + "$" + propertyPath);
            }

            return(r);
        }