Пример #1
0
        /// <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;
        }
Пример #2
0
 /// <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)
 {
 }
Пример #3
0
 /// <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="flags">One of the APXmlPropertyOptions enumeration values.</param>
 public APXmlProperty(string name, Type type, object defaultValue, APXmlPropertyOptions flags)
     : this(name, type, defaultValue,
            TypeDescriptor.GetConverter(type), new DefaultAPValidator(), flags, null)
 {
 }
Пример #4
0
		/// <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)
		{
		}
Пример #5
0
		/// <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="flags">One of the APXmlPropertyOptions enumeration values.</param>
		public APXmlProperty(string name, Type type, object defaultValue, APXmlPropertyOptions flags)
			: this(name, type, defaultValue,
			TypeDescriptor.GetConverter(type), new DefaultAPValidator(), flags, null)
		{
		}
Пример #6
0
		/// <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;
		}