public ValidationModel(PropertyModel propertyModel, IPropertyAttribute attribute, MethodInfo methodForValidation) { string message = attribute.GetValidationMessage(); SetMessage(message); SetFunction(propertyModel, attribute, methodForValidation); }
public PropertyController(IProperty propertyService , ISystemJob systemJobService , IPropertyAttribute propertyAttributeService) { this.propertyService = propertyService; this.systemJobService = systemJobService; this.propertyAttributeService = propertyAttributeService; }
public PropertyAttributesViewComponent(IPropertyAttribute PropertyAttributeService , IEPCRating EPCRatingService , ITenureType TenureTypeService , IPropertyType PropertyTypeService) { this.PropertyAttributeService = PropertyAttributeService; this.EPCRatingService = EPCRatingService; this.TenureTypeService = TenureTypeService; this.PropertyTypeService = PropertyTypeService; }
public PropertyAttributeController(IPropertyAttribute PropertyAttributeService , IEPCRating EPCRatingService , ITenureType TenureTypeService , IPropertyType PropertyTypeService ) { this.PropertyAttributeService = PropertyAttributeService; this.EPCRatingService = EPCRatingService; this.TenureTypeService = TenureTypeService; this.PropertyTypeService = PropertyTypeService; }
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); }
private void BindValidation(PropertyModel propertyModel) { Type typeOfModelToValidate = propertyModel.ReferencedModelType; foreach (object attribute in propertyModel.Attributes) { IPropertyAttribute baseAttribute = attribute as BasePropertyAttribute; if (baseAttribute != null) { IValidationModel validationModel = MakeValidationModel(propertyModel, baseAttribute); validationCollection[typeOfModelToValidate].Add(validationModel); } } }
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 IModelProperty GetModelProperty(PropertyInfo propertyInfo, IPropertyAttribute attribute) { if (propertyInfo == null) { throw new ArgumentNullException("propertyInfo"); } //if (attribute == null) throw new ArgumentNullException("attribute"); var modelType = propertyInfo.PropertyType; Type elementType; bool isArray = false; bool isCollection = false; bool isEnumerable = false; Action <object, object> addToCollection = null; Func <IEnumerable, Array> toArray = null; if (isArray = helper.IsArray(modelType, out elementType)) //Array is ICollection<> and IEnumerable { modelType = elementType; toArray = helper.BuildToArray(elementType); } else if (isCollection = helper.IsGenericCollection(modelType, out elementType)) //ICollection<> is IEnumerable { addToCollection = helper.BuildAddMethod(modelType); modelType = elementType; } else { isEnumerable = helper.IsEnumerable(propertyInfo.PropertyType); //Fallback to plain IEnumerable } return(new ModelProperty { Name = propertyInfo.Name, PropertyAttribute = attribute, Set = helper.BuildSetter(propertyInfo), Get = helper.BuildGetter(propertyInfo), PropertyType = propertyInfo.PropertyType, IsEnumerable = isEnumerable, IsCollection = isCollection, IsArray = isArray, ModelType = modelType, AddToCollection = addToCollection, ToArray = toArray }); }
public MethodInfo FindSpecificMethod(string type, Type attributeType) { MethodInfo specificMethod = null; type = type.ToLower(); if (methodsForValidation[type].Count > 0) { foreach (MethodInfo method in methodsForValidation[type]) { IPropertyAttribute attribute = (IPropertyAttribute)method.GetCustomAttribute(attributeType); if (attribute != null) { specificMethod = method; break; } } } return(specificMethod); }
private MethodCallExpression GenerateMethodCallExpression(IPropertyAttribute attribute, MethodInfo validationMethod, Expression expressionForValidation) { AttributeType type = attribute.GetAttributeType(); MethodCallExpression exp = null; switch (type) { case AttributeType.Required: exp = ValidationExpressionGenerator.GenerateRequiredExpression(validationMethod, expressionForValidation); break; case AttributeType.RangeLength: exp = ValidationExpressionGenerator.GenerateLengthRangeExpression((LengthPropertyAttribute)attribute, validationMethod, expressionForValidation); break; default: throw new InvalidEnumArgumentException("There is no expression for specified enum queryType!"); } return(exp); }
public IModelProperty GetModelProperty <TSource, TProperty>(Expression <Func <TSource, TProperty> > propertyLambda, IPropertyAttribute attribute) { return(GetModelProperty(helper.GetPropertyInfo <TSource, TProperty>(propertyLambda), attribute)); }
public PropertyMapping(PropertyInfo property, IPropertyAttribute propertyAttribute, Action <IPropertyAttribute, IBindingContainer> getMapping) { Property = property; PropertyAttribute = propertyAttribute; GetMapping = getMapping; }
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)) { }
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)) { }