public override void Init(ExtensionsOptions <T> options)
        {
            var f = new RuleFactory <T>();

            foreach (var p in ReflectionHelper.GetProperties <T>())
            {
                foreach (var a in p.GetCustomAttributes(typeof(ValidationAttribute), true))
                {
                    var selector = PrecompilationHelper.GetPropertySelector <T>(p);

                    var a2 = (ValidationAttribute)a;

                    var    l    = new List <ValidationResult>();
                    string name = p.Name;
                    var    rule = f.CreateValidationRuleWithoutDependency(
                        t =>
                        Validator.TryValidateValue(selector(t),
                                                   new ValidationContext(t, null, null)
                    {
                        MemberName = name, DisplayName = name
                    }, l, new[] { a2 }))
                                  .WithDependencies(name);

                    rule.WithLocalizableMessage(t => l.First().ErrorMessage);

                    options.RulePrototypes.Add(rule);
                }
            }
        }
Пример #2
0
        public override void Init(ExtensionsOptions <T> options)
        {
#if PHONE
            // throw new NotImplementedException("EntityBaseRecursiveStrategy reflection");
#else
            options.RecursiveStrategy = new EntityBaseRecursiveStrategy <T>();
#endif
        }
        public override void Init(ExtensionsOptions <T> options)
        {
#if PHONE
            // throw new NotImplementedException("EntityBaseGraphMonitoringExtensionPoint reflection");
#else
            options.GraphMonitoringStrategy = new EntityBaseGraphMonitoringStrategy <T>();
#endif
        }
 public override void Init(ExtensionsOptions <T> options)
 {
     foreach (var method in ReflectionHelper.GetMethodsWithAttributeOfType <T, RuleInitAttribute>())
     {
         if (ReflectionHelper.IsMethod(method, false, typeof(void)))
         {
             // Rule init method
             var param = Expression.Parameter(typeof(T), "t");
             var f     = Expression.Lambda <Action <T> >(
                 Expression.Call(param, method), param);
             options.RuleInitializers.Add(f.Compile());
         }
     }
 }
 public override void Init(ExtensionsOptions <T> options)
 {
     foreach (var method in ReflectionHelper.GetMethodsWithAttributeOfType <T, RuleInitAttribute>())
     {
         if (ReflectionHelper.IsMethod(method, true, typeof(IEnumerable <Rule>), typeof(Type)))
         {
             // Rule prototype
             var res = (IEnumerable <Rule>)method.Invoke(null, new[] { typeof(T) });
             foreach (var rule in res)
             {
                 options.RulePrototypes.Add(rule);
             }
         }
     }
 }
        public override void Init(ExtensionsOptions <T> options)
        {
            foreach (var method in ReflectionHelper.GetMethodsWithAttributeOfType <T, RuleDecoratorAttribute>())
            {
                if (ReflectionHelper.IsMethod(method, true, typeof(void), typeof(Rule)))
                {
                    var param = Expression.Parameter(typeof(Rule), "r");
                    var f     = Expression.Lambda <Action <Rule> >(
                        Expression.Call(method, param), param);

                    options.Decorators.Add(f.Compile());
                }
                else
                {
                    throw new InvalidOperationException("Invalid method signature.");
                }
            }
        }
Пример #7
0
 public override void Init(ExtensionsOptions <T> options)
 {
     foreach (var method in ReflectionHelper.GetMethodsWithAttributeOfType <T, PropertiesInitAttribute>())
     {
         if (ReflectionHelper.IsMethod(method, false, typeof(void)))
         {
             // Properties init method
             var param = Expression.Parameter(typeof(T), "t");
             var f     = Expression.Lambda <Action <T> >(
                 Expression.Call(param, method), param);
             options.PropertyInitializers.Add(f.Compile());
         }
         else
         {
             throw new InvalidOperationException("Invalid method signature.");
         }
     }
 }
Пример #8
0
        public override void Init(ExtensionsOptions <T> options)
        {
            var f = new RuleFactory <T>();

            foreach (var p in ReflectionHelper.GetProperties <T>())
            {
                foreach (PropertyValidationAttribute attribute in p.GetCustomAttributes(typeof(PropertyValidationAttribute), true))
                {
                    attribute.ValidatePropertyUsage(p);

                    // optimize
                    var selector = PrecompilationHelper.GetPropertySelector <T>(p);

                    var rule = attribute.CreateRule(p, f, selector);

                    options.RulePrototypes.Add(rule);
                }
            }
        }
 public override void Init(ExtensionsOptions <T> options)
 {
     options.GraphMonitoringStrategy = NoGraphMonitoringStrategy.Instance;
 }
Пример #10
0
 public override void Init(ExtensionsOptions <T> options)
 {
     options.RulePrototypes.AddRange(Prototypes);
 }
Пример #11
0
 public override void Init(ExtensionsOptions <T> options)
 {
     options.PropertyInitializers.Add(PropertyInit);
 }
 public override void Init(ExtensionsOptions <T> options)
 {
     options.Decorators.Add(Decorator);
 }