Esempio n. 1
0
		private OptionConfigurationElement EnsureElementPropertyValue(OptionConfigurationProperty property)
		{
			if(property == null)
				throw new ArgumentNullException("property");

			object value = null;

			lock(_values)
			{
				_values.TryGetValue(property, out value);

				if(value == null)
				{
					//如果当前配置属性定义项的类型不是一个选项配置元素,则抛出异常。因为所有复合类型必须从选项配置元素继承
					if(!typeof(OptionConfigurationElement).IsAssignableFrom(property.Type))
						throw new OptionConfigurationException();

					//根据配置属性定义项的类型创建其对应的目标对象
					if(property.Type.IsGenericType && property.Type.GetGenericTypeDefinition() == typeof(OptionConfigurationElementCollection<>))
						value = Activator.CreateInstance(property.Type, new object[] { property.ElementName, null });
					else
						value = Activator.CreateInstance(property.Type);

					//设置创建的选项配置元素对象的表示其自身的属性定义项
					((OptionConfigurationElement)value)._elementProperty = property;

					//将创建的目标对象保存到对应的属性值中
					_values[property] = value;
				}
			}

			return (OptionConfigurationElement)value;
		}
Esempio n. 2
0
        protected internal object this[OptionConfigurationProperty property]
        {
            get
            {
                if (property == null)
                {
                    throw new ArgumentNullException("property");
                }

                object value;

                if (_values.TryGetValue(property, out value))
                {
                    return(value);
                }

                return(property.DefaultValue);
            }
            set
            {
                this.SetPropertyValue(property, value);

                //激发“PropertyChanged”事件
                this.RaisePropertyChanged(property.Name);
            }
        }
Esempio n. 3
0
        private void SetPropertyValue(OptionConfigurationProperty property, object value)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (object.Equals(value, property.DefaultValue))
            {
                _values.Remove(property);
            }
            else
            {
                if (property.Type.IsAssignableFrom(value.GetType()))
                {
                    _values[property] = value;
                }
                else
                {
                    if (property.Converter == null)
                    {
                        _values[property] = Zongsoft.Common.Convert.ConvertValue(value, property.Type, property.DefaultValue);
                    }
                    else
                    {
                        _values[property] = property.Converter.ConvertFrom(value);
                    }
                }
            }
        }
		static TracerElement()
		{
			_enabled = new OptionConfigurationProperty("enabled", typeof(bool), true);
			_listeners = new OptionConfigurationProperty("listeners", typeof(TraceListenerElementCollection), null);
			_properties = new OptionConfigurationPropertyCollection();
			_properties.Add(_enabled);
			_properties.Add(_listeners);
		}
Esempio n. 5
0
		private static OptionConfigurationProperty CreateOptionPropertyFromAttribute(PropertyInfo propertyInfo)
		{
			OptionConfigurationProperty result = null;

			var attribute = (OptionConfigurationPropertyAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(OptionConfigurationPropertyAttribute));

			if(attribute != null)
				result = new OptionConfigurationProperty(propertyInfo);

			return result;
		}
            public void Add(string name, string value)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    throw new ArgumentNullException("name");
                }

                if (_unrecognizedProperties.Contains(name))
                {
                    throw new OptionConfigurationException(string.Format("The '{0}' attribute is existed.", name));
                }

                var property = new OptionConfigurationProperty(name, typeof(string));

                _element.Properties.Add(property);
                _element.SetPropertyValue(property, value);

                _unrecognizedProperties.Add(name);
            }
		protected internal object this[OptionConfigurationProperty property]
		{
			get
			{
				if(property == null)
					throw new ArgumentNullException("property");

				object value;

				if(_values.TryGetValue(property, out value))
					return value;

				return property.DefaultValue;
			}
			set
			{
				this.SetPropertyValue(property, value);

				//激发“PropertyChanged”事件
				this.RaisePropertyChanged(property.Name);
			}
		}
		private void SetPropertyValue(OptionConfigurationProperty property, object value)
		{
			if(property == null)
				throw new ArgumentNullException("property");

			if(object.Equals(value, property.DefaultValue))
				_values.Remove(property);
			else
			{
				if(property.Type.IsAssignableFrom(value.GetType()))
					_values[property] = value;
				else
				{
					if(property.Converter == null)
						_values[property] = Zongsoft.Common.Convert.ConvertValue(value, property.Type, property.DefaultValue);
					else
						_values[property] = property.Converter.ConvertFrom(value);
				}
			}
		}