Пример #1
0
        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);
            }
        }
Пример #2
0
		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);
			}
		}
Пример #3
0
        /// <summary>
        /// Specifies whether the configuration property is contained in this collection.
        /// </summary>
        /// <param name="name">An identifier for the APGenProperty to verify.</param>
        /// <returns>true if the specified APGenProperty is contained in the collection; otherwise, false.</returns>
        public bool Contains(string name)
        {
            APGenProperty property = this[name];

            if (property == null)
            {
                return(false);
            }

            return(_collection.Contains(property));
        }
Пример #4
0
        private void ValidateValue(APGenProperty property, string value)
        {
            APValidatorBase validator;

            if (property == null || (validator = property.Validator) == null)
                return;

            if (!validator.CanValidate(property.Type))
                throw new APGenException(APResource.GetString(APResource.APGen_ValidatorNotSupportType, property.Type));
            validator.Validate(property.ConvertFromString(value));
        }
Пример #5
0
 /// <summary>
 /// Set property value.
 /// </summary>
 /// <param name="prop">Property</param>
 /// <param name="value">Value</param>
 protected void SetPropertyValue(APGenProperty prop, object value)
 {
     try
     {
         prop.Validate(value);
     }
     catch (Exception e)
     {
         throw new APGenException(APResource.GetString(APResource.APGen_PropertyValueInvalid, prop.Name, e.Message), e);
     }
 }
Пример #6
0
		static APGenAlias()
		{
			nameProp = new APGenProperty(
				"name",
				typeof(string),
				null,
				APCVHelper.WhiteSpaceTrimStringConverter,
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
				);


			properties = new APGenPropertyCollection();
			properties.Add(nameProp);
		}
Пример #7
0
        static APGenAlias()
        {
            nameProp = new APGenProperty(
                "name",
                typeof(string),
                null,
                APCVHelper.WhiteSpaceTrimStringConverter,
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
                );


            properties = new APGenPropertyCollection();
            properties.Add(nameProp);
        }
Пример #8
0
        static APGenIndex()
        {
            nameProp = new APGenProperty(
                "name",
                typeof(string),
                null,
                APCVHelper.WhiteSpaceTrimStringConverter,
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
                );
            isDefaultProp = new APGenProperty("isDefault", typeof(bool), false);
            ordersProp    = new APGenProperty("", typeof(APGenOrderCollection), null, null, null, APGenPropertyOptions.IsDefaultCollection);


            properties = new APGenPropertyCollection();
            properties.Add(nameProp);
            properties.Add(isDefaultProp);
            properties.Add(ordersProp);
        }
Пример #9
0
		static APGenIndex()
		{
			nameProp = new APGenProperty(
				"name",
				typeof(string),
				null,
				APCVHelper.WhiteSpaceTrimStringConverter,
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
				);
			isDefaultProp = new APGenProperty("isDefault", typeof(bool), false);
			ordersProp = new APGenProperty("", typeof(APGenOrderCollection), null, null, null, APGenPropertyOptions.IsDefaultCollection);


			properties = new APGenPropertyCollection();
			properties.Add(nameProp);
			properties.Add(isDefaultProp);
			properties.Add(ordersProp);
		}
Пример #10
0
        internal APGenElementCollection GetDefaultCollection()
        {
            if (_defaultCollection != null)
                return _defaultCollection;

            APGenProperty defaultCollectionProp = null;

            foreach (APGenProperty prop in Properties)
            {
                if (prop.IsDefaultCollection)
                {
                    defaultCollectionProp = prop;
                    break;
                }
            }

            if (defaultCollectionProp != null)
                _defaultCollection = this[defaultCollectionProp] as APGenElementCollection;
            return _defaultCollection;
        }
Пример #11
0
		static APGenTable()
		{
			nameProp = new APGenProperty(
				"name",
				typeof(string),
				null, 
				APCVHelper.WhiteSpaceTrimStringConverter, 
				APCVHelper.NonEmptyStringValidator, 
				APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
				);
			tableNameProp = new APGenProperty("tableName", typeof(string));
			classNameProp = new APGenProperty("className", typeof(string));
			dataInheritFromBaseProp = new APGenProperty("dataInheritFromBase", typeof(bool), true);
			dalInheritFromBaseProp = new APGenProperty("dalInheritFromBase", typeof(bool), true);
			bplInheritFromBaseProp = new APGenProperty("bplInheritFromBase", typeof(bool), true);
			inheritsProp = new APGenProperty("inherits", typeof(string), "");
			commentProp = new APGenProperty("comment", typeof(string));
			columnsProp = new APGenProperty("columns", typeof(APGenColumnCollection));
			indexesProp = new APGenProperty("indexes", typeof(APGenIndexCollection));
			uniquesProp = new APGenProperty("uniques", typeof(APGenIndexCollection));
			aliasesProp = new APGenProperty("aliases", typeof(APGenAliasCollection));


			properties = new APGenPropertyCollection();
			properties.Add(nameProp);
			properties.Add(tableNameProp);
			properties.Add(classNameProp);
			properties.Add(dataInheritFromBaseProp);
			properties.Add(dalInheritFromBaseProp);
			properties.Add(bplInheritFromBaseProp);
			properties.Add(inheritsProp);
			properties.Add(commentProp);
			properties.Add(columnsProp);
			properties.Add(indexesProp);
			properties.Add(uniquesProp);
			properties.Add(aliasesProp);
		}
Пример #12
0
        static APGenTable()
        {
            nameProp = new APGenProperty(
                "name",
                typeof(string),
                null,
                APCVHelper.WhiteSpaceTrimStringConverter,
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
                );
            tableNameProp           = new APGenProperty("tableName", typeof(string));
            classNameProp           = new APGenProperty("className", typeof(string));
            dataInheritFromBaseProp = new APGenProperty("dataInheritFromBase", typeof(bool), true);
            dalInheritFromBaseProp  = new APGenProperty("dalInheritFromBase", typeof(bool), true);
            bplInheritFromBaseProp  = new APGenProperty("bplInheritFromBase", typeof(bool), true);
            inheritsProp            = new APGenProperty("inherits", typeof(string), "");
            commentProp             = new APGenProperty("comment", typeof(string));
            columnsProp             = new APGenProperty("columns", typeof(APGenColumnCollection));
            indexesProp             = new APGenProperty("indexes", typeof(APGenIndexCollection));
            uniquesProp             = new APGenProperty("uniques", typeof(APGenIndexCollection));
            aliasesProp             = new APGenProperty("aliases", typeof(APGenAliasCollection));


            properties = new APGenPropertyCollection();
            properties.Add(nameProp);
            properties.Add(tableNameProp);
            properties.Add(classNameProp);
            properties.Add(dataInheritFromBaseProp);
            properties.Add(dalInheritFromBaseProp);
            properties.Add(bplInheritFromBaseProp);
            properties.Add(inheritsProp);
            properties.Add(commentProp);
            properties.Add(columnsProp);
            properties.Add(indexesProp);
            properties.Add(uniquesProp);
            properties.Add(aliasesProp);
        }
Пример #13
0
        static APGenOrder()
        {
            nameProp = new APGenProperty(
                "name",
                typeof(string),
                null,
                APCVHelper.WhiteSpaceTrimStringConverter,
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
                );
            accordingProp = new APGenProperty(
                "according",
                typeof(APSqlOrderAccording),
                APSqlOrderAccording.Asc,
                new GenericEnumAPConverter(typeof(APSqlOrderAccording)),
                APCVHelper.DefaultValidator,
                APGenPropertyOptions.None
                );


            properties = new APGenPropertyCollection();
            properties.Add(nameProp);
            properties.Add(accordingProp);
        }
Пример #14
0
		static APGenOrder()
		{
			nameProp = new APGenProperty(
				"name",
				typeof(string),
				null,
				APCVHelper.WhiteSpaceTrimStringConverter,
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
				);
			accordingProp = new APGenProperty(
				"according",
				typeof(APSqlOrderAccording),
				APSqlOrderAccording.Asc,
				new GenericEnumAPConverter(typeof(APSqlOrderAccording)),
				APCVHelper.DefaultValidator,
				APGenPropertyOptions.None
				);


			properties = new APGenPropertyCollection();
			properties.Add(nameProp);
			properties.Add(accordingProp);
		}
Пример #15
0
		static APGenRelation()
		{
			nameProp = new APGenProperty(
				"name",
				typeof(string),
				null,
				APCVHelper.WhiteSpaceTrimStringConverter,
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
				);
			masterTableProp = new APGenProperty(
				"masterTable",
				typeof(string),
				"",
				TypeDescriptor.GetConverter(typeof(string)),
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.IsRequired
				);
			masterColumnProp = new APGenProperty(
				"masterColumn",
				typeof(string),
				"",
				TypeDescriptor.GetConverter(typeof(string)),
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.IsRequired
				);
			slaveTableProp = new APGenProperty(
				"slaveTable",
				typeof(string),
				"",
				TypeDescriptor.GetConverter(typeof(string)),
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.IsRequired
				);
			slaveColumnProp = new APGenProperty(
				"slaveColumn",
				typeof(string),
				"",
				TypeDescriptor.GetConverter(typeof(string)),
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.IsRequired
				);
			cascadeTypeProp = new APGenProperty(
				"cascadeType",
				typeof(APRelationCascadeType),
				APRelationCascadeType.None,
				new GenericEnumAPConverter(typeof(APRelationCascadeType)),
				APCVHelper.DefaultValidator,
				APGenPropertyOptions.None
				);
			commentProp = new APGenProperty("comment", typeof(string));


			properties = new APGenPropertyCollection();
			properties.Add(nameProp);
			properties.Add(masterTableProp);
			properties.Add(masterColumnProp);
			properties.Add(slaveTableProp);
			properties.Add(slaveColumnProp);
			properties.Add(cascadeTypeProp);
			properties.Add(commentProp);
		}
Пример #16
0
		/// <summary>
		/// Get or set value by property.
		/// </summary>
		/// <param name="property">Property.</param>
		/// <returns>Value</returns>
		protected internal object this[APGenProperty property]
		{
			get { return this[property.Name]; }
			set { this[property.Name] = value; }
		}
Пример #17
0
		static APGenColumn()
		{
			nameProp = new APGenProperty(
				"name", 
				typeof(string), 
				null, 
				APCVHelper.WhiteSpaceTrimStringConverter, 
				APCVHelper.NonEmptyStringValidator, 
				APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
				);
			columnNameProp = new APGenProperty("columnName", typeof(string));
			propertyNameProp = new APGenProperty("propertyName", typeof(string));
			typeProp = new APGenProperty(
				"type",
				typeof(string),
				"string",
				TypeDescriptor.GetConverter(typeof(string)),
				APCVHelper.NonEmptyStringValidator,
				APGenPropertyOptions.None
				);
			isEnumProp = new APGenProperty("isEnum", typeof(bool), false);
			defaultValueProp = new APGenProperty("defaultValue", typeof(string), "");
			overrideProp = new APGenProperty("override", typeof(bool), false);
			identityTypeProp = new APGenProperty(
				"identityType",
				typeof(APColumnIdentityType),
				APColumnIdentityType.None,
				new GenericEnumAPConverter(typeof(APColumnIdentityType)),
				APCVHelper.DefaultValidator, 
				APGenPropertyOptions.None
				);
			providerIdentityBaseProp = new APGenProperty("providerIdentityBase", typeof(int), 5000);
			isNullableProp = new APGenProperty("isNullable", typeof(bool), false);
			primaryKeyProp = new APGenProperty("primaryKey", typeof(bool), false);
			dbTypeProp = new APGenProperty(
				"dbType",
				typeof(DbType),
				DbType.Object,
				new GenericEnumAPConverter(typeof(DbType)),
				APCVHelper.DefaultValidator, 
				APGenPropertyOptions.None
				);
			dbDefaultValueProp = new APGenProperty("dbDefaultValue", typeof(string));
			dataLengthProp = new APGenProperty("dataLength", typeof(int), 0);
			precisionProp = new APGenProperty("precision", typeof(int), 18);
			scaleProp = new APGenProperty("scale", typeof(int), 0);
			commentProp = new APGenProperty("comment", typeof(string));
			displayProp = new APGenProperty("display", typeof(string));
			requiredProp = new APGenProperty("required", typeof(bool));


			properties = new APGenPropertyCollection();
			properties.Add(nameProp);
			properties.Add(columnNameProp);
			properties.Add(propertyNameProp);
			properties.Add(typeProp);
			properties.Add(isEnumProp);
			properties.Add(defaultValueProp);
			properties.Add(overrideProp);
			properties.Add(identityTypeProp);
			properties.Add(providerIdentityBaseProp);
			properties.Add(isNullableProp);
			properties.Add(primaryKeyProp);
			properties.Add(dbTypeProp);
			properties.Add(dbDefaultValueProp);
			properties.Add(dataLengthProp);
			properties.Add(precisionProp);
			properties.Add(scaleProp);
			properties.Add(commentProp);
			properties.Add(displayProp);
			properties.Add(requiredProp);
		}
Пример #18
0
 /// <summary>
 /// Get or set value by property.
 /// </summary>
 /// <param name="property">Property.</param>
 /// <returns>Value</returns>
 protected internal object this[APGenProperty property]
 {
     get { return this[property.Name]; }
     set { this[property.Name] = value; }
 }
Пример #19
0
 /// <summary>
 /// Adds a configuration property to the collection.
 /// </summary>
 /// <param name="property">The APGenProperty to add.</param>
 public void Add(APGenProperty property)
 {
     _collection.Add(property);
 }
		internal APGenPropertyInformation(APGenElement owner, APGenProperty property)
		{
			_owner = owner;
			_property = property;
		}
Пример #21
0
		/// <summary>
		/// Adds a configuration property to the collection.
		/// </summary>
		/// <param name="property">The APGenProperty to add.</param>
		public void Add(APGenProperty property)
		{
			_collection.Add(property);
		}
Пример #22
0
		/// <summary>
		/// Copies this APGenPropertyCollection to an array.
		/// </summary>
		/// <param name="array">Array to which to copy.</param>
		/// <param name="index">Index at which to begin copying.</param>
		public void CopyTo(APGenProperty[] array, int index)
		{
			_collection.CopyTo(array, index);
		}
Пример #23
0
 internal APGenPropertyInformation(APGenElement owner, APGenProperty property)
 {
     _owner    = owner;
     _property = property;
 }
Пример #24
0
		/// <summary>
		/// Set property value.
		/// </summary>
		/// <param name="prop">Property</param>
		/// <param name="value">Value</param>
		protected void SetPropertyValue(APGenProperty prop, object value)
		{
			try
			{
				prop.Validate(value);
			}
			catch (Exception e)
			{
				throw new APGenException(APResource.GetString(APResource.APGen_PropertyValueInvalid, prop.Name, e.Message), e);
			}
		}
Пример #25
0
        static APGenColumn()
        {
            nameProp = new APGenProperty(
                "name",
                typeof(string),
                null,
                APCVHelper.WhiteSpaceTrimStringConverter,
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
                );
            columnNameProp   = new APGenProperty("columnName", typeof(string));
            propertyNameProp = new APGenProperty("propertyName", typeof(string));
            typeProp         = new APGenProperty(
                "type",
                typeof(string),
                "string",
                TypeDescriptor.GetConverter(typeof(string)),
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.None
                );
            isEnumProp       = new APGenProperty("isEnum", typeof(bool), false);
            defaultValueProp = new APGenProperty("defaultValue", typeof(string), "");
            overrideProp     = new APGenProperty("override", typeof(bool), false);
            identityTypeProp = new APGenProperty(
                "identityType",
                typeof(APColumnIdentityType),
                APColumnIdentityType.None,
                new GenericEnumAPConverter(typeof(APColumnIdentityType)),
                APCVHelper.DefaultValidator,
                APGenPropertyOptions.None
                );
            providerIdentityBaseProp = new APGenProperty("providerIdentityBase", typeof(int), 5000);
            isNullableProp           = new APGenProperty("isNullable", typeof(bool), false);
            primaryKeyProp           = new APGenProperty("primaryKey", typeof(bool), false);
            dbTypeProp = new APGenProperty(
                "dbType",
                typeof(DbType),
                DbType.Object,
                new GenericEnumAPConverter(typeof(DbType)),
                APCVHelper.DefaultValidator,
                APGenPropertyOptions.None
                );
            dbDefaultValueProp = new APGenProperty("dbDefaultValue", typeof(string));
            dataLengthProp     = new APGenProperty("dataLength", typeof(int), 0);
            precisionProp      = new APGenProperty("precision", typeof(int), 18);
            scaleProp          = new APGenProperty("scale", typeof(int), 0);
            commentProp        = new APGenProperty("comment", typeof(string));
            displayProp        = new APGenProperty("display", typeof(string));
            requiredProp       = new APGenProperty("required", typeof(bool));


            properties = new APGenPropertyCollection();
            properties.Add(nameProp);
            properties.Add(columnNameProp);
            properties.Add(propertyNameProp);
            properties.Add(typeProp);
            properties.Add(isEnumProp);
            properties.Add(defaultValueProp);
            properties.Add(overrideProp);
            properties.Add(identityTypeProp);
            properties.Add(providerIdentityBaseProp);
            properties.Add(isNullableProp);
            properties.Add(primaryKeyProp);
            properties.Add(dbTypeProp);
            properties.Add(dbDefaultValueProp);
            properties.Add(dataLengthProp);
            properties.Add(precisionProp);
            properties.Add(scaleProp);
            properties.Add(commentProp);
            properties.Add(displayProp);
            properties.Add(requiredProp);
        }
Пример #26
0
		private void ValidateValue(APGenProperty property, string value)
		{
			APValidatorBase validator;

			if (property == null || (validator = property.Validator) == null)
				return;

			if (!validator.CanValidate(property.Type))
				throw new APGenException(APResource.GetString(APResource.APGen_ValidatorNotSupportType, property.Type));
			validator.Validate(property.ConvertFromString(value));
		}
Пример #27
0
        static APGenRelation()
        {
            nameProp = new APGenProperty(
                "name",
                typeof(string),
                null,
                APCVHelper.WhiteSpaceTrimStringConverter,
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired | APGenPropertyOptions.IsKey
                );
            masterTableProp = new APGenProperty(
                "masterTable",
                typeof(string),
                "",
                TypeDescriptor.GetConverter(typeof(string)),
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired
                );
            masterColumnProp = new APGenProperty(
                "masterColumn",
                typeof(string),
                "",
                TypeDescriptor.GetConverter(typeof(string)),
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired
                );
            slaveTableProp = new APGenProperty(
                "slaveTable",
                typeof(string),
                "",
                TypeDescriptor.GetConverter(typeof(string)),
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired
                );
            slaveColumnProp = new APGenProperty(
                "slaveColumn",
                typeof(string),
                "",
                TypeDescriptor.GetConverter(typeof(string)),
                APCVHelper.NonEmptyStringValidator,
                APGenPropertyOptions.IsRequired
                );
            cascadeTypeProp = new APGenProperty(
                "cascadeType",
                typeof(APRelationCascadeType),
                APRelationCascadeType.None,
                new GenericEnumAPConverter(typeof(APRelationCascadeType)),
                APCVHelper.DefaultValidator,
                APGenPropertyOptions.None
                );
            commentProp = new APGenProperty("comment", typeof(string));


            properties = new APGenPropertyCollection();
            properties.Add(nameProp);
            properties.Add(masterTableProp);
            properties.Add(masterColumnProp);
            properties.Add(slaveTableProp);
            properties.Add(slaveColumnProp);
            properties.Add(cascadeTypeProp);
            properties.Add(commentProp);
        }