public void HandleElement(XElement ancestor) { if (ancestor == null) { throw new ArgumentNullException("ancestor"); } if (!ElementName.Equals(ancestor.Name.LocalName, StringComparison.OrdinalIgnoreCase)) { throw new XmlConfigurationException(ancestor, "Unexpected element '{0}' (expecting '{1}').", ancestor.Name.LocalName, ElementName); } IList <T> result = new List <T>(); foreach (XElement element in ancestor.Elements()) { string typeName = element.Name.LocalName; if (!_collector.Value.Contains(typeName)) { throw new XmlConfigurationException(element, "Unknown element"); } ConfigurationTypeInfo typeInfo = _collector.Value.GetTypeInfo(typeName); IConfigurationData <T> data = typeInfo.CreateInstance <IConfigurationData <T> >(); var attributes = element.Attributes().Select(x => new KeyValuePair <string, string>(x.Name.LocalName, x.Value)); var subelements = element.Elements().Select(x => new KeyValuePair <string, string>(x.Name.LocalName, x.Value)); foreach (var kv in attributes.Concat(subelements)) { SetPropertyValue(element, typeInfo, data, kv.Key, kv.Value); } T item = data.CreateObject(); string id = GetItemId(item); if (_items.ContainsKey(id)) { throw new XmlConfigurationException(element, "Duplicate item (id '{0}') found.", id); } _items.Add(id, item); } }
/// <inheritdoc/> public bool Equals(PointerName other) { return(ElementName.Equals(other.ElementName) && Kind == other.Kind); }