public static Dictionary <string, MappingInfo> GetFieldMappings(Type type) { Dictionary <string, MappingInfo> dictionary = new Dictionary <string, MappingInfo>(); foreach (PropertyInfo propertyInfo in type.GetProperties()) { PropertyMappingAttribute propertyMappingAttribute = Attribute.GetCustomAttribute((MemberInfo)propertyInfo, typeof(PropertyMappingAttribute)) as PropertyMappingAttribute ?? new PropertyMappingAttribute(propertyInfo.Name); dictionary.Add(propertyMappingAttribute.Name, (MappingInfo) new PropertyMappingInfo(propertyMappingAttribute, propertyInfo)); } foreach (FieldInfo fieldInfo in type.GetFields()) { FieldMappingAttribute fieldMappingAttribute = Attribute.GetCustomAttribute((MemberInfo)fieldInfo, typeof(FieldMappingAttribute)) as FieldMappingAttribute ?? new FieldMappingAttribute(fieldInfo.Name); dictionary.Add(fieldMappingAttribute.Name, (MappingInfo) new FieldMappingInfo(fieldMappingAttribute, fieldInfo)); } return(dictionary); }
public PropertyMappingInfo(PropertyMappingAttribute propertyMappingAttribute, PropertyInfo propertyInfo) { this.PropertyMappingAttribute = propertyMappingAttribute; this.PropertyInfo = propertyInfo; }