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; }
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)) { }
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)) { }
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); }