public APGenElementMap(Type type) { _properties = new APGenPropertyCollection(); _collectionAttribute = Attribute.GetCustomAttribute(type, typeof(APGenCollectionAttribute)) as APGenCollectionAttribute; PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); foreach (PropertyInfo prop in props) { APGenPropertyAttribute attr = Attribute.GetCustomAttribute(prop, typeof(APGenPropertyAttribute)) as APGenPropertyAttribute; if (attr == null) { continue; } string name = attr.Name != null ? attr.Name : prop.Name; APValidatorAttribute validatorAttr = Attribute.GetCustomAttribute(prop, typeof(APValidatorAttribute)) as APValidatorAttribute; APValidatorBase validator = validatorAttr != null ? validatorAttr.ValidatorInstance : null; TypeConverterAttribute convertAttr = Attribute.GetCustomAttribute(prop, typeof(TypeConverterAttribute)) as TypeConverterAttribute; TypeConverter converter = convertAttr != null ? (TypeConverter)Activator.CreateInstance(Type.GetType(convertAttr.ConverterTypeName), true) : null; APGenProperty property = new APGenProperty(name, prop.PropertyType, attr.DefaultValue, converter, validator, attr.Options); property.CollectionAttribute = Attribute.GetCustomAttribute(prop, typeof(APGenCollectionAttribute)) as APGenCollectionAttribute; _properties.Add(property); } }
public APGenElementMap(Type type) { _properties = new APGenPropertyCollection(); _collectionAttribute = Attribute.GetCustomAttribute(type, typeof(APGenCollectionAttribute)) as APGenCollectionAttribute; PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); foreach (PropertyInfo prop in props) { APGenPropertyAttribute attr = Attribute.GetCustomAttribute(prop, typeof(APGenPropertyAttribute)) as APGenPropertyAttribute; if (attr == null) continue; string name = attr.Name != null ? attr.Name : prop.Name; APValidatorAttribute validatorAttr = Attribute.GetCustomAttribute(prop, typeof(APValidatorAttribute)) as APValidatorAttribute; APValidatorBase validator = validatorAttr != null ? validatorAttr.ValidatorInstance : null; TypeConverterAttribute convertAttr = Attribute.GetCustomAttribute(prop, typeof(TypeConverterAttribute)) as TypeConverterAttribute; TypeConverter converter = convertAttr != null ? (TypeConverter)Activator.CreateInstance(Type.GetType(convertAttr.ConverterTypeName), true) : null; APGenProperty property = new APGenProperty(name, prop.PropertyType, attr.DefaultValue, converter, validator, attr.Options); property.CollectionAttribute = Attribute.GetCustomAttribute(prop, typeof(APGenCollectionAttribute)) as APGenCollectionAttribute; _properties.Add(property); } }
internal override void InitFromProperty(APGenPropertyInformation propertyInfo) { APGenCollectionAttribute attr = propertyInfo.Property.CollectionAttribute; if (attr == null) { attr = Attribute.GetCustomAttribute(propertyInfo.Type, typeof(APGenCollectionAttribute)) as APGenCollectionAttribute; } if (attr != null) { _addElementName = attr.AddItemName; } base.InitFromProperty(propertyInfo); }