示例#1
0
        //  //TODO 3467:
        //  // StringPropertyAttribute
        //  public class StringxxxValidationRule : xxxValidationRule<StringPropertyAttribute>
        //  {
        //    override string GetMEssage()
        //  }

        //  protected MappingValidationResultValidate (PropertyInfo pi)
        //{
        //    var attr = AttributeUtility.GetCustomAttributes<TAttribute> (pi, true))
        //    if (attr != null && !IsPropertyTypeSupported (pi))
        //    {
        //        return new MappingValidationResult (false, GetMessage (pi));
        //    }
        //    return new MappingValidationResult (true);
        //  }

        private MappingValidationResult Validate(IPropertyInformation propertyInfo)
        {
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);

            foreach (var attribute in propertyInfo.GetCustomAttributes <Attribute> (true))
            {
                var constraint = GetAttributeConstraint(attribute.GetType());
                if (constraint != null && !Array.Exists(constraint.PropertyTypes, t => IsPropertyTypeSupported(propertyInfo, t)))
                {
                    return(MappingValidationResult.CreateInvalidResultForProperty(propertyInfo, constraint.Message));
                }
            }
            return(MappingValidationResult.CreateValidResult());
        }
        private MappingValidationResult Validate(IPropertyInformation propertyInfo)
        {
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);

            if (!propertyInfo.IsOriginalDeclaration())
            {
                var mappingAttributes = propertyInfo.GetCustomAttributes <IMappingAttribute> (false);
                if (mappingAttributes.Any())
                {
                    return(MappingValidationResult.CreateInvalidResultForProperty(
                               propertyInfo,
                               "The '{0}' is a mapping attribute and may only be applied at the property's base definition.",
                               mappingAttributes[0].GetType().Name));
                }
            }
            return(MappingValidationResult.CreateValidResult());
        }
 protected override bool FindPropertiesFilter(IPropertyInformation propertyInfo)
 {
     ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);
     return(propertyInfo.GetCustomAttributes <IMappingAttribute> (false).Any());
 }
 public T[] GetCustomAttributes <T> (bool inherited) where T : class
 {
     return(_implementationPropertyInfo.GetCustomAttributes <T> (inherited));
 }