/// <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> /// <returns>none</returns> public static List <T> FindExtensions <T>(ExtensionList arrList, string localName, string ns) where T : IExtensionElementFactory { List <T> list = new List <T>(); if (arrList == null) { throw new ArgumentNullException("arrList"); } foreach (IExtensionElementFactory obj in arrList) { if (obj is T) { T ele = (T)obj; // only if the elements do implement the ExtensionElementFactory // do we know if it's xml name/namespace if (ele != null) { if (compareXmlNess(ele.XmlName, localName, ele.XmlNameSpace, ns)) { list.Add(ele); } } } } return(list); }
/// <summary> /// Deletes all Extensions from the Extension list that match /// a localName and a Namespace. /// </summary> /// <param name="localName">the local name to find</param> /// <param name="ns">the namespace to match, if null, ns is ignored</param> /// <returns>int - the number of deleted extensions</returns> public int DeleteExtensions(string localName, string ns) { // Find them first ExtensionList arr = FindExtensions(localName, ns); foreach (IExtensionElementFactory ob in arr) { this.ExtensionElements.Remove(ob); } return(arr.Count); }
/// <summary> /// takes an object and set's the version number to the /// same as this instance /// </summary> /// <param name="arr">The array of objects the version should be applied to</param> public void ImprintVersion(ExtensionList arr) { if (arr == null) { return; } foreach (Object o in arr) { IVersionAware v = o as IVersionAware; if (v != null) { ImprintVersion(v); } } }
/// <summary> /// Finds a specific ExtensionElement based on it's local name /// and it's namespace. If namespace is NULL, the first one where /// 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> /// <returns>Object</returns> public static IExtensionElementFactory FindExtension(ExtensionList arrList, string localName, string ns) { if (arrList == null) { return(null); } foreach (IExtensionElementFactory ele in arrList) { if (compareXmlNess(ele.XmlName, localName, ele.XmlNameSpace, ns)) { return(ele); } } return(null); }
/// <summary> /// all extension elements that match a namespace/localname /// given will be removed and replaced with the new ones. /// the input array can contain several different /// namespace/localname combinations /// if the passed list is NULL or empty, this will just result /// in additions /// </summary> /// <param name="newList">a list of xmlnodes or IExtensionElementFactory objects</param> /// <returns>int - the number of deleted extensions</returns> public int ReplaceExtensions(ExtensionList newList) { int count = 0; // get rid of all of the old ones matching the specs if (newList != null) { foreach (Object ob in newList) { string localName = null; string ns = null; XmlNode node = ob as XmlNode; if (node != null) { localName = node.LocalName; ns = node.NamespaceURI; } else { IExtensionElementFactory ele = ob as IExtensionElementFactory; if (ele != null) { localName = ele.XmlName; ns = ele.XmlNameSpace; } } if (localName != null) { count += DeleteExtensions(localName, ns); } } // now add the new ones foreach (IExtensionElementFactory ob in newList) { this.ExtensionElements.Add(ob); } } return(count); }
/// <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> /// Finds all ExtensionElement based on local name /// and namespace. If namespace is NULL, all where /// the localname matches is found. If there are extensionelements that do /// not implement ExtensionElementFactory, they will not be taken into account /// Primary use of this is to find XML nodes /// </summary> /// <param name="localName">the xml local name of the element to find</param> /// <param name="ns">the namespace of the element to find</param> /// <param name="arr">the array to fill</param> /// <returns>none</returns> public ExtensionList FindExtensions(string localName, string ns, ExtensionList arr) { return(Utilities.FindExtensions(this.ExtensionElements, localName, ns, arr)); }