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)
        {
            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);
                }
            }
        }
示例#3
0
 public EntityBaseGraphMonitoringStrategy()
 {
     foreach (var p in ReflectionHelper.GetProperties <T>()
              .Where(p => HasTraversal(typeof(T), p)))
     {
         if ((typeof(IEntityBase).IsAssignableFrom(p.PropertyType)))
         {
             var propertySelector = PrecompilationHelper
                                    .GetPropertySelector <object>(p);
             Properties.Add(p.Name, propertySelector);
         }
         var paramType = p.PropertyType.GetIEnumerableGenericParam();
         if (paramType != null)
         {
             if ((typeof(IEntityBase).IsAssignableFrom(paramType)))
             {
                 Func <object, IEnumerable> collectionSelector = PrecompilationHelper.GetPropertySelector <object, IEnumerable>(p);
                 Collections.Add(p.Name, collectionSelector);
             }
         }
     }
 }
示例#4
0
 public CompareValidation(PropertyInfo propertyInfo)
 {
     _func = PrecompilationHelper.GetPropertySelector(propertyInfo);
 }