Beispiel #1
0
        /// <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>
        /// <param name="description">The description of the configuration entity.</param>
        public APGenProperty(string name, Type type, object defaultValue, TypeConverter converter, APValidatorBase validation, APGenPropertyOptions 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 APGenException(APResource.GetString(APResource.APGen_DefaultValueTypeError, name, type, defaultValue.GetType()));
                        }
                        defaultValue = _converter.ConvertFrom(defaultValue);
                    }
                }
            }

            _defaultValue = defaultValue;
            _flags        = flags;
            _type         = type;
            _validation   = validation != null ? validation : new DefaultAPValidator();
            _description  = description;
        }
Beispiel #2
0
 /// <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)
 {
 }
Beispiel #3
0
 /// <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="flags">One of the APGenPropertyOptions enumeration values.</param>
 public APGenProperty(string name, Type type, object defaultValue, APGenPropertyOptions flags)
     : this(name, type, defaultValue, TypeDescriptor.GetConverter(type), new DefaultAPValidator(), flags, null)
 {
 }
Beispiel #4
0
		/// <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>
		/// <param name="description">The description of the configuration entity.</param>
		public APGenProperty(string name, Type type, object defaultValue, TypeConverter converter, APValidatorBase validation, APGenPropertyOptions 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 APGenException(APResource.GetString(APResource.APGen_DefaultValueTypeError, name, type, defaultValue.GetType()));
						defaultValue = _converter.ConvertFrom(defaultValue);
					}
				}
			}

			_defaultValue = defaultValue;
			_flags = flags;
			_type = type;
			_validation = validation != null ? validation : new DefaultAPValidator();
			_description = description;
		}
Beispiel #5
0
		/// <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)
		{ }
Beispiel #6
0
		/// <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="flags">One of the APGenPropertyOptions enumeration values.</param>
		public APGenProperty(string name, Type type, object defaultValue, APGenPropertyOptions flags)
			: this(name, type, defaultValue, TypeDescriptor.GetConverter(type), new DefaultAPValidator(), flags, null)
		{ }