/////////////////////////////////////////////////////////////////////// /// <summary>Replaces or adds an extension of the given type /// to the list. /// /// This method looks for the first element on the list of the /// given type and replaces it with the new value. If there are /// no element of this type yet, a new element is added at the /// end of the list. /// </summary> /// <param name="extensionElements">list of IExtensionElement</param> /// <param name="type">type of the element to be added, removed /// or replaced</param> /// <param name="newValue">new value for this element, null to /// remove it</param> /////////////////////////////////////////////////////////////////////// public static void SetExtension(IList<IExtensionElementFactory> extensionElements, Type type, IExtensionElementFactory newValue) { int count = extensionElements.Count; for (int i = 0; i < count; i++) { object element = extensionElements[i]; if (type.IsInstanceOfType(element)) { if (newValue == null) { extensionElements.RemoveAt(i); } else { extensionElements[i] = newValue; } return; } } if (newValue != null) { extensionElements.Add(newValue); } }
/// <summary> /// Finds all ExtensionElement based on it's local name /// and it's namespace. If namespace is NULL, allwhere /// the localname matches is found. If there are extensionelements that do /// not implment ExtensionElementFactory, they will not be taken into account /// Primary use of this is to find XML nodes /// </summary> /// <param name="arrList">the array to search through</param> /// <param name="localName">the xml local name of the element to find</param> /// <param name="ns">the namespace of the elementToPersist</param> /// <param name="arr">the array to fill</param> /// <returns>none</returns> public static ExtensionList FindExtensions(ExtensionList arrList, string localName, string ns, ExtensionList arr) { if (arrList == null) { throw new ArgumentNullException("arrList"); } if (arr == null) { throw new ArgumentNullException("arr"); } foreach (IExtensionElementFactory ob in arrList) { XmlNode node = ob as XmlNode; if (node != null) { if (compareXmlNess(node.LocalName, localName, node.NamespaceURI, ns)) { arr.Add(ob); } } else { // only if the elements do implement the ExtensionElementFactory // do we know if it's xml name/namespace IExtensionElementFactory ele = ob as IExtensionElementFactory; if (ele != null) { if (compareXmlNess(ele.XmlName, localName, ele.XmlNameSpace, ns)) { arr.Add(ob); } } } } return(arr); }
/// <summary> /// Parses the inner state of the element /// </summary> /// <param name="e">The extension element that should be added to this entry</param> /// <param name="parser">The AtomFeedParser that called this</param> public virtual void Parse(ExtensionElementEventArgs e, AtomFeedParser parser) { if (e == null) { throw new ArgumentNullException("e"); } Tracing.TraceMsg("Entering Parse on AbstractEntry"); XmlNode node = e.ExtensionElement; if (ExtensionFactories != null && ExtensionFactories.Count > 0) { Tracing.TraceMsg("Entring default Parsing for AbstractEntry"); IExtensionElementFactory f = FindExtensionFactory( node.LocalName, node.NamespaceURI); if (f != null) { ExtensionElements.Add(f.CreateInstance(node, parser)); e.DiscardEntry = true; } } }
/// <summary> /// all extension elements that match a namespace/localname /// given will be removed and the new one will be inserted /// </summary> /// <param name="localName">the local name to find</param> /// <param name="ns">the namespace to match, if null, ns is ignored</param> /// <param name="obj">the new element to put in</param> public void ReplaceExtension (string localName, string ns, IExtensionElementFactory obj) { DeleteExtensions(localName, ns); this.ExtensionElements.Add(obj); }
private String GenerateXml(IExtensionElementFactory ext) { StringWriter sw = new StringWriter(); XmlWriter xmlw = new XmlTextWriter(sw); ext.Save(xmlw); xmlw.Close(); return sw.ToString(); }
/// <summary> /// all extension elements that match a namespace/localname /// given will be removed and the new one will be inserted /// </summary> /// <param name="localName">the local name to find</param> /// <param name="ns">the namespace to match, if null, ns is ignored</param> /// <param name="obj">the new element to put in</param> public void ReplaceExtension(string localName, string ns, IExtensionElementFactory obj) { DeleteExtensions(localName, ns); this.ExtensionElements.Add(obj); }
/// <summary> /// all extension element factories that match a namespace/localname /// given will be removed and the new one will be inserted /// </summary> /// <param name="localName">the local name to find</param> /// <param name="ns">the namespace to match, if null, ns is ignored</param> /// <param name="obj">the new element to put in</param> public void ReplaceFactory(string localName, string ns, IExtensionElementFactory obj) { ExtensionList arr = Utilities.FindExtensions(this.ExtensionFactories, localName, ns, new ExtensionList(this)); foreach (IExtensionElementFactory ob in arr) { this.ExtensionFactories.Remove(ob); } this.ExtensionFactories.Add(obj); }