public static InvalidXmlAttributeException Create(Type type, IFieldPropertyInfo property, Type attribute, string customMessage)
        {
            string message = $"{type.FullName}.{property.Name} has an invalid attribute {attribute.FullName} " +
                             $"applied based on its type. Reason: {customMessage} Assembly: {type.AssemblyQualifiedName}";

            return(new InvalidXmlAttributeException(message));
        }
示例#2
0
        public void Validate(IFieldPropertyInfo property, Type parentType, AbstractAttributeContext context)
        {
            XmlPropertyAttributeContext xmlContext = (XmlPropertyAttributeContext)context;
            Type type = property.Type;

            if (xmlContext.HasXmlFlattenHierarchyAttribute && !type.IsClass)
            {
                throw InvalidXmlAttributeException.Create(parentType, property, typeof(XmlFlattenHierarchyAttribute), FLATTEN_HIERARCHY_REASON_ERROR);
            }

            if (xmlContext.HasXmlListAttribute && !type.IsCollection())
            {
                throw InvalidXmlAttributeException.Create(parentType, property, typeof(XmlListAttribute), LIST_REASON_ERROR);
            }

            if (xmlContext.HasXmlDictionaryAttribute && !type.IsDictionary())
            {
                throw InvalidXmlAttributeException.Create(parentType, property, typeof(XmlDictionaryAttribute), DICTIONARY_REASON_ERROR);
            }

            if (!xmlContext.HasXmlDictionaryAttribute && type.IsDictionary() && type.GenericTypeArguments[0].Equals(typeof(String)))
            {
                throw InvalidXmlMappingException.Create(parentType, property, DICTIONARY_AUTOMAP_REASON_ERROR);
            }
        }
        public PropertyAttributeContext(IFieldPropertyInfo property)
            : base(property)
        {
            Property = property;
            PropertyConverterAttribute = GetAttribute <PropertyConverterAttribute>();
            NameAttribute = GetAttribute <NameAttribute>();

            HasPropertyConverterAttribute = PropertyConverterAttribute != null;
            HasNameAttribute   = NameAttribute != null;
            HasIgnoreAttribute = ContainsAttribute <IgnoreAttribute>();
        }
示例#4
0
        public XmlPropertyAttributeContext(IFieldPropertyInfo property) : base(property)
        {
            XmlListAttribute = GetAttribute <XmlListAttribute>();
            XmlPropertyConverterAttribute = GetAttribute <XmlPropertyConverterAttribute>();
            XmlFlattenHierarchyAttribute  = GetAttribute <XmlFlattenHierarchyAttribute>();
            XmlDictionaryAttribute        = GetAttribute <XmlDictionaryAttribute>();

            HasXmlListAttribute = XmlListAttribute != null;
            HasXmlPropertyConverterAttribute = XmlPropertyConverterAttribute != null;
            HasXmlFlattenHierarchyAttribute  = XmlFlattenHierarchyAttribute != null;
            HasXmlDictionaryAttribute        = XmlDictionaryAttribute != null;
        }
示例#5
0
 public ConcurrentDictionaryTypeContext GetContextsForProperty(IFieldPropertyInfo property)
 {
     return(_propertyContexts[property]);
 }
示例#6
0
 public bool HasPropertyAttributeContext <AttributeContextType>(IFieldPropertyInfo property)
 {
     return(_propertyContexts.ContainsKey(property) && _propertyContexts[property].ContainsKey(typeof(AttributeContextType)));
 }
示例#7
0
 public AttributeContextType GetAttributeContextForProperty <AttributeContextType>(IFieldPropertyInfo property) where AttributeContextType : AbstractAttributeContext
 {
     return((AttributeContextType)_propertyContexts[property][typeof(AttributeContextType)]);
 }
        public static InvalidXmlMappingException Create(Type parentType, IFieldPropertyInfo property, string reason)
        {
            string message = $"{parentType.FullName}.{property.Name} cannot be mapped - {reason}";

            return(new InvalidXmlMappingException(message));
        }
示例#9
0
 public AbstractAttributeContext(IFieldPropertyInfo propertyInfo) : this()
 {
     AddAttributes(ReflectionUtils.GetCustomAttributes <IAttributeMarker>(propertyInfo));
 }
示例#10
0
 public static AttributeType[] GetCustomAttributes <AttributeType>(IFieldPropertyInfo fieldPropertyInfo)
 {
     object[] attributes = fieldPropertyInfo.GetCustomAttributes(typeof(AttributeType), true);
     return((AttributeType[])Convert.ChangeType(attributes, typeof(AttributeType[])));
 }
示例#11
0
 public static Attribute[] GetCustomAttributes(IFieldPropertyInfo fieldPropertyInfo)
 {
     return(GetCustomAttributes <Attribute>(fieldPropertyInfo));
 }
示例#12
0
 public static bool HasCustomAttributeType(Type type, IFieldPropertyInfo fieldPropertyInfo)
 {
     return(GetCustomAttributes(type, fieldPropertyInfo).Length > 0);
 }
示例#13
0
 public static bool HasCustomAttributeType <AttributeType>(IFieldPropertyInfo fieldPropertyInfo)
 {
     return(GetCustomAttributes <AttributeType>(fieldPropertyInfo).Length > 0);
 }
示例#14
0
 public static object[] GetCustomAttributes(Type type, IFieldPropertyInfo fieldPropertyInfo)
 {
     return(fieldPropertyInfo.GetCustomAttributes(type, true));
 }