예제 #1
0
        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);
        }
예제 #2
0
 public DynamicProxy(IStaticProxy proxy)
 {
     if (proxy == null)
     {
         throw new ArgumentNullException("proxy");
     }
     Proxy = proxy;
 }
예제 #3
0
 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));
 }
예제 #4
0
 public ValidatingProxy(IStaticProxy proxy, IPropertyValidator propertyValidator = null) : base(proxy)
 {
     ValidateOnChange = true;
     SetPropertyValidator(propertyValidator);
 }
예제 #5
0
 public NotifyingProxy(IStaticProxy proxy) : base(proxy)
 {
 }
예제 #6
0
 private FullAccessProxy(IStaticProxy proxy) : base(proxy)
 {
 }
예제 #7
0
 public EditableProxy(IStaticProxy proxy) : base(proxy)
 {
 }
예제 #8
0
 public DataErrorInfoProxy(IStaticProxy proxy, IPropertyValidator propertyValidator = null) : base(proxy, propertyValidator)
 {
 }