Beispiel #1
0
        public void SetFunction(PropertyModel propertyModel, IPropertyAttribute attribute, MethodInfo validationMethod)
        {
            Func <T, bool>       predicate = null;
            MethodCallExpression validator = null;
            Type typeOfViewModel           = propertyModel.ReferencedModelType;
            Type typeOfAttribute           = attribute.GetType();

            ParameterExpression pe  = Expression.Parameter(typeOfViewModel, "instance");
            Expression          exp = Expression.Call(pe, propertyModel.Property.GetGetMethod());

            validator = GenerateMethodCallExpression(attribute, validationMethod, exp);
            predicate = Expression.Lambda <Func <T, bool> >(validator, pe).Compile();

            function = predicate;
        }
Beispiel #2
0
 public PropertyTypeMismatchException(IModelProperty fieldProperty, IPropertyAttribute fieldAttribute, object fieldValue)
     : base(String.Format("Type mismatch for property '{0}'. Expected type for '{1}' is {2}. Model Property is of type {3}. Field value is of type {4}."
     , fieldProperty.Name, fieldAttribute.GetType().Name, fieldAttribute.ExpectedReturnType.FullName, fieldProperty.PropertyType.FullName,
     fieldValue.GetType().FullName))
 {
 }
Beispiel #3
0
 public PropertyTypeMismatchException(IModelProperty fieldProperty, IPropertyAttribute fieldAttribute, object fieldValue) :
     base(String.Format("Type mismatch for property '{0}'. Expected type for '{1}' is {2}. Model Property is of type {3}. Field value is of type {4}."
                        , fieldProperty.Name, fieldAttribute.GetType().Name, fieldAttribute.ExpectedReturnType.FullName, fieldProperty.PropertyType.FullName,
                        fieldValue == null ? "" : fieldValue.GetType().FullName))
 {
 }
Beispiel #4
0
        private IValidationModel MakeValidationModel(PropertyModel propertyModel, IPropertyAttribute attribute)
        {
            Type       type = typeof(ValidationModel <>).MakeGenericType(propertyModel.ReferencedModelType);
            MethodInfo methodForValidation = FindSpecificMethod(propertyModel.PropertyType, attribute.GetType());

            object[] param = new[] { (object)propertyModel, (object)attribute, (object)methodForValidation };

            object instance = Activator.CreateInstance(type, param);

            return((IValidationModel)instance);
        }