Пример #1
0
		public APXmlElementMap(Type type)
		{
			_properties = new APXmlPropertyCollection();

			_collectionAttribute = Attribute.GetCustomAttribute(type, typeof(APXmlCollectionAttribute)) as APXmlCollectionAttribute;

			PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);

			foreach (PropertyInfo prop in props)
			{
				APXmlPropertyAttribute attr = Attribute.GetCustomAttribute(prop, typeof(APXmlPropertyAttribute)) as APXmlPropertyAttribute;
				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;

				APXmlProperty property = new APXmlProperty(name, prop.PropertyType, attr.DefaultValue, converter, validator, attr.Options);

				property.CollectionAttribute = Attribute.GetCustomAttribute(prop, typeof(APXmlCollectionAttribute)) as APXmlCollectionAttribute;
				_properties.Add(property);
			}
		}
Пример #2
0
        public APXmlElementMap(Type type)
        {
            _properties = new APXmlPropertyCollection();

            _collectionAttribute = Attribute.GetCustomAttribute(type, typeof(APXmlCollectionAttribute)) as APXmlCollectionAttribute;

            PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);

            foreach (PropertyInfo prop in props)
            {
                APXmlPropertyAttribute attr = Attribute.GetCustomAttribute(prop, typeof(APXmlPropertyAttribute)) as APXmlPropertyAttribute;
                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;

                APXmlProperty property = new APXmlProperty(name, prop.PropertyType, attr.DefaultValue, converter, validator, attr.Options);

                property.CollectionAttribute = Attribute.GetCustomAttribute(prop, typeof(APXmlCollectionAttribute)) as APXmlCollectionAttribute;
                _properties.Add(property);
            }
        }
Пример #3
0
        internal override void InitFromProperty(APXmlPropertyInformation propertyInfo)
        {
            APXmlCollectionAttribute attr = propertyInfo.Property.CollectionAttribute;

            if (attr == null)
            {
                attr = Attribute.GetCustomAttribute(propertyInfo.Type, typeof(APXmlCollectionAttribute)) as APXmlCollectionAttribute;
            }

            if (attr != null)
            {
                _addElementName = attr.AddItemName;
            }

            base.InitFromProperty(propertyInfo);
        }