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)); }
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>(); }
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; }
public ConcurrentDictionaryTypeContext GetContextsForProperty(IFieldPropertyInfo property) { return(_propertyContexts[property]); }
public bool HasPropertyAttributeContext <AttributeContextType>(IFieldPropertyInfo property) { return(_propertyContexts.ContainsKey(property) && _propertyContexts[property].ContainsKey(typeof(AttributeContextType))); }
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)); }
public AbstractAttributeContext(IFieldPropertyInfo propertyInfo) : this() { AddAttributes(ReflectionUtils.GetCustomAttributes <IAttributeMarker>(propertyInfo)); }
public static AttributeType[] GetCustomAttributes <AttributeType>(IFieldPropertyInfo fieldPropertyInfo) { object[] attributes = fieldPropertyInfo.GetCustomAttributes(typeof(AttributeType), true); return((AttributeType[])Convert.ChangeType(attributes, typeof(AttributeType[]))); }
public static Attribute[] GetCustomAttributes(IFieldPropertyInfo fieldPropertyInfo) { return(GetCustomAttributes <Attribute>(fieldPropertyInfo)); }
public static bool HasCustomAttributeType(Type type, IFieldPropertyInfo fieldPropertyInfo) { return(GetCustomAttributes(type, fieldPropertyInfo).Length > 0); }
public static bool HasCustomAttributeType <AttributeType>(IFieldPropertyInfo fieldPropertyInfo) { return(GetCustomAttributes <AttributeType>(fieldPropertyInfo).Length > 0); }
public static object[] GetCustomAttributes(Type type, IFieldPropertyInfo fieldPropertyInfo) { return(fieldPropertyInfo.GetCustomAttributes(type, true)); }