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); } }
/// <summary> /// Creates a new instance of the ConfigurationProperty class. /// </summary> /// <param name="name">The name of the xml entity.</param> /// <param name="type">The type of the xml entity.</param> /// <param name="defaultValue">The default value of the xml entity.</param> /// <param name="converter">The type of the converter to apply.</param> /// <param name="validation">The validator to use.</param> /// <param name="flags">One of the APXmlPropertyOptions enumeration values.</param> /// <param name="description">The description of the xml entity.</param> public APXmlProperty(string name, Type type, object defaultValue, TypeConverter converter, APValidatorBase validation, APXmlPropertyOptions flags, string description) { _name = name; _converter = converter != null ? converter : TypeDescriptor.GetConverter(type); if (defaultValue != null) { if (defaultValue == NoDefaultValue) { switch (Type.GetTypeCode(type)) { case TypeCode.Object: defaultValue = null; break; case TypeCode.String: defaultValue = String.Empty; break; default: defaultValue = Activator.CreateInstance(type); break; } } else { if (!type.IsAssignableFrom(defaultValue.GetType())) { if (!_converter.CanConvertFrom(defaultValue.GetType())) { throw new APXmlException(APResource.GetString(APResource.APXml_DefaultValueTypeError, name, type, defaultValue.GetType())); } defaultValue = _converter.ConvertFrom(defaultValue); } } } _defaultValue = defaultValue; _flags = flags; _type = type; _validation = validation != null ? validation : new DefaultAPValidator(); _description = description; }
/// <summary> /// Initializes a new instance of the APGenElementProperty class, based on a supplied parameter. /// </summary> /// <param name="validator">A APValidatorBase object.</param> public APGenElementProperty(APValidatorBase validator) { _validator = validator; }
/// <summary> /// Initializes a new instance of the APGenProperty class. /// </summary> /// <param name="name">The name of the configuration entity.</param> /// <param name="type">The type of the configuration entity.</param> /// <param name="defaultValue">The default value of the configuration entity.</param> /// <param name="converter">The type of the converter to apply.</param> /// <param name="validation">The validator to use.</param> /// <param name="flags">One of the APGenPropertyOptions enumeration values.</param> public APGenProperty(string name, Type type, object defaultValue, TypeConverter converter, APValidatorBase validation, APGenPropertyOptions flags) : this(name, type, defaultValue, converter, validation, flags, null) { }
/// <summary> /// Creates a new instance of the ConfigurationProperty class. /// </summary> /// <param name="name">The name of the xml entity.</param> /// <param name="type">The type of the xml entity.</param> /// <param name="defaultValue">The default value of the xml entity.</param> /// <param name="converter">The type of the converter to apply.</param> /// <param name="validation">The validator to use.</param> /// <param name="flags">One of the APXmlPropertyOptions enumeration values.</param> public APXmlProperty(string name, Type type, object defaultValue, TypeConverter converter, APValidatorBase validation, APXmlPropertyOptions flags) : this(name, type, defaultValue, converter, validation, flags, null) { }
/// <summary> /// Creates a new instance of the ConfigurationProperty class. /// </summary> /// <param name="name">The name of the xml entity.</param> /// <param name="type">The type of the xml entity.</param> /// <param name="defaultValue">The default value of the xml entity.</param> /// <param name="converter">The type of the converter to apply.</param> /// <param name="validation">The validator to use.</param> /// <param name="flags">One of the APXmlPropertyOptions enumeration values.</param> /// <param name="description">The description of the xml entity.</param> public APXmlProperty(string name, Type type, object defaultValue, TypeConverter converter, APValidatorBase validation, APXmlPropertyOptions flags, string description) { _name = name; _converter = converter != null ? converter : TypeDescriptor.GetConverter(type); if (defaultValue != null) { if (defaultValue == NoDefaultValue) { switch (Type.GetTypeCode(type)) { case TypeCode.Object: defaultValue = null; break; case TypeCode.String: defaultValue = String.Empty; break; default: defaultValue = Activator.CreateInstance(type); break; } } else { if (!type.IsAssignableFrom(defaultValue.GetType())) { if (!_converter.CanConvertFrom(defaultValue.GetType())) throw new APXmlException(APResource.GetString(APResource.APXml_DefaultValueTypeError, name, type, defaultValue.GetType())); defaultValue = _converter.ConvertFrom(defaultValue); } } } _defaultValue = defaultValue; _flags = flags; _type = type; _validation = validation != null ? validation : new DefaultAPValidator(); _description = description; }