示例#1
0
 public OptionConfigurationPropertyAttribute(string name, Type type, object defaultValue = null, OptionConfigurationPropertyBehavior behavior = OptionConfigurationPropertyBehavior.None)
 {
     _name         = name == null ? string.Empty : name.Trim();
     _type         = type;
     _defaultValue = defaultValue;
     _behavior     = behavior;
 }
		public OptionConfigurationPropertyAttribute(string name, Type type, object defaultValue, OptionConfigurationPropertyBehavior behavior, TypeConverter converter)
		{
			_name = name == null ? string.Empty : name.Trim();
			_type = type;
			_defaultValue = defaultValue;
			_behavior = behavior;
			_converter = converter;
		}
        public OptionConfigurationProperty(string name, Type type, object defaultValue = null, OptionConfigurationPropertyBehavior behavior = OptionConfigurationPropertyBehavior.None, TypeConverter converter = null)
        {
            _name      = name == null ? string.Empty : name.Trim();
            _type      = type ?? throw new ArgumentNullException(nameof(type));
            _behavior  = behavior;
            _converter = converter;

            //注意:要最后设置默认属性的值
            this.DefaultValue = defaultValue;
        }
		public OptionConfigurationProperty(string name, Type type, object defaultValue, OptionConfigurationPropertyBehavior behavior, TypeConverter converter)
		{
			if(type == null)
				throw new ArgumentNullException("type");

			_name = name == null ? string.Empty : name.Trim();
			_type = type;
			_behavior = behavior;
			_converter = converter;

			//注意:要最后设置默认属性的值
			this.DefaultValue = defaultValue;
		}
示例#5
0
        internal OptionConfigurationProperty(PropertyInfo propertyInfo)
        {
            OptionConfigurationPropertyAttribute propertyAttribute = null;
            TypeConverterAttribute converterAttribute = null;
            DefaultValueAttribute  defaultAttribute   = null;

            var attributes = propertyInfo.GetCustomAttributes();

            foreach (var attribute in attributes)
            {
                if (attribute is OptionConfigurationPropertyAttribute)
                {
                    propertyAttribute = (OptionConfigurationPropertyAttribute)attribute;
                }
                else if (attribute is DefaultValueAttribute)
                {
                    defaultAttribute = (DefaultValueAttribute)attribute;
                }
                else if (attribute is TypeConverterAttribute)
                {
                    converterAttribute = (TypeConverterAttribute)attribute;
                }
            }

            _name        = propertyAttribute.Name;
            _elementName = propertyAttribute.ElementName;
            _type        = propertyAttribute.Type ?? propertyInfo.PropertyType;
            _behavior    = propertyAttribute.Behavior;

            if (propertyAttribute.Converter != null)
            {
                _converter = propertyAttribute.Converter;
            }
            else
            {
                if (converterAttribute != null && !string.IsNullOrEmpty(converterAttribute.ConverterTypeName))
                {
                    Type type = Type.GetType(converterAttribute.ConverterTypeName, false);

                    if (type != null)
                    {
                        _converter = Activator.CreateInstance(type, true) as TypeConverter;
                    }
                }
            }

            //注意:要最后设置默认属性的值
            this.DefaultValue = defaultAttribute != null ? defaultAttribute.Value : propertyAttribute.DefaultValue;
        }
示例#6
0
 public OptionConfigurationPropertyAttribute(string name, OptionConfigurationPropertyBehavior behavior) : this(name, null, null, behavior, null)
 {
 }
示例#7
0
 public OptionConfigurationProperty(string name, Type type, object defaultValue, OptionConfigurationPropertyBehavior behavior) : this(name, type, defaultValue, behavior, null)
 {
 }
		internal OptionConfigurationProperty(PropertyInfo propertyInfo)
		{
			OptionConfigurationPropertyAttribute propertyAttribute = null;
			System.ComponentModel.TypeConverterAttribute converterAttribute = null;
			System.ComponentModel.DefaultValueAttribute defaultAttribute = null;

			foreach(var attribute in Attribute.GetCustomAttributes(propertyInfo))
			{
				if(attribute is OptionConfigurationPropertyAttribute)
					propertyAttribute = (OptionConfigurationPropertyAttribute)attribute;
				else if(attribute is System.ComponentModel.DefaultValueAttribute)
					defaultAttribute = (System.ComponentModel.DefaultValueAttribute)attribute;
				else if(attribute is System.ComponentModel.TypeConverterAttribute)
					converterAttribute = (System.ComponentModel.TypeConverterAttribute)attribute;
			}

			_name = propertyAttribute.Name;
			_elementName = propertyAttribute.ElementName;
			_type = propertyAttribute.Type ?? propertyInfo.PropertyType;
			_behavior = propertyAttribute.Behavior;

			if(propertyAttribute.Converter != null)
				_converter = propertyAttribute.Converter;
			else
			{
				if(converterAttribute != null && !string.IsNullOrEmpty(converterAttribute.ConverterTypeName))
				{
					Type type = Type.GetType(converterAttribute.ConverterTypeName, false);

					if(type != null)
						_converter = Activator.CreateInstance(type, true) as TypeConverter;
				}
			}

			//注意:要最后设置默认属性的值
			this.DefaultValue = defaultAttribute != null ? defaultAttribute.Value : propertyAttribute.DefaultValue;
		}
		public OptionConfigurationProperty(string name, Type type, object defaultValue, OptionConfigurationPropertyBehavior behavior) : this(name, type, defaultValue, behavior, null)
		{
		}
示例#10
0
 public OptionConfigurationPropertyAttribute(string name, object defaultValue, OptionConfigurationPropertyBehavior behavior = OptionConfigurationPropertyBehavior.None) : this(name, null, defaultValue, behavior)
 {
 }
		public OptionConfigurationPropertyAttribute(string name, OptionConfigurationPropertyBehavior behavior) : this(name, null, null, behavior, null)
		{
		}