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);
            }
Exemple #2
0
        private void DeserializeAttributes(XmlReader reader, OptionConfigurationElement element)
        {
            OptionConfigurationProperty property;

            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            var elementName = reader.Name;

            for (int i = 0; i < reader.AttributeCount; i++)
            {
                reader.MoveToAttribute(i);

                //XML特性名中间含点的,并且是以表示是以元素名打头的,则表示为系统内置特性因而无需解析处理
                if (reader.Name.StartsWith(elementName + "."))
                {
                    continue;
                }

                //获取当前XML元素特性对应的配置属性定义项
                if (element.Properties.TryGetValue(reader.Name, out property))
                {
                    element.SetPropertyValue(property, reader.Value);
                }
                else
                {
                    //执行处理未知的属性反序列化
                    if (!element.OnDeserializeUnrecognizedAttribute(reader.Name, reader.Value))
                    {
                        throw new OptionConfigurationException(string.Format("The '{0}' option configuration attribute is unrecognized.", reader.Name));
                    }
                }
            }

            //将当前读取器移到元素上
            reader.MoveToElement();
        }