public bool Validate(IStaticProxy proxy, string propertyName, object value, ICollection <ValidationResult> validationResults) { Debug.Assert(proxy != null, "Valid proxy should be specified"); Debug.Assert(proxy.ProxiedObject != null, "Proxy should wrap valid object"); var info = GlobalTypeInfoCache.GetTypeInfo(proxy.ProxiedObject.GetType()).GetPropertyInfo(propertyName); var validationAttributes = GetAttributes(info); if (validationAttributes.Count() == 0) { return(true); } var validationContext = new ValidationContext(proxy.ProxiedObject, null, null); var isValid = Validator.TryValidateValue(value, validationContext, validationResults, validationAttributes); if (isValid) { var propertyType = proxy.GetPropertyType(propertyName); try { if (propertyType != value.GetType()) { Convert.ChangeType(value, propertyType); } } catch (Exception) { validationResults.Add(new ValidationResult("Cannot convert value to type " + propertyType)); isValid = false; } } return(isValid); }
public DynamicProxy(IStaticProxy proxy) { if (proxy == null) { throw new ArgumentNullException("proxy"); } Proxy = proxy; }
public virtual IEnumerable <string> GetValidationProperties(IStaticProxy proxy) { if (proxy == null) { throw new ArgumentNullException("proxy"); } Debug.Assert(proxy.ProxiedObject != null, "Proxy should wrap valid object"); return(proxy.ProxiedObject.GetType().GetProperties().Where(pi => GetAttributes(pi).Any()).Select(pi => pi.Name)); }
public ValidatingProxy(IStaticProxy proxy, IPropertyValidator propertyValidator = null) : base(proxy) { ValidateOnChange = true; SetPropertyValidator(propertyValidator); }
public NotifyingProxy(IStaticProxy proxy) : base(proxy) { }
private FullAccessProxy(IStaticProxy proxy) : base(proxy) { }
public EditableProxy(IStaticProxy proxy) : base(proxy) { }
public DataErrorInfoProxy(IStaticProxy proxy, IPropertyValidator propertyValidator = null) : base(proxy, propertyValidator) { }