public void ToXNameTest()
        {
            // Arrange
            const string name     = "TestName";
            XDocument    document = new XDocument(new XElement("root", new XElement("record", new XElement("testName", "testing"))));

            // Act
            XName xName = name.ToXName(document);

            // Assert
            Assert.Equal(name.ToLower(), xName?.ToString().ToLower());
        }
Exemplo n.º 2
0
        // return a string of the form "{http://my.namespace}TagName"
        internal override string GetXElementTagName(object item)
        {
            XName name = ((XElement)item).Name;

            return((name != null) ? name.ToString() : null);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Returns a filtered collection of the attributes of every element in the source
 /// collection. Only elements that have a matching <see cref="System.Xml.Linq.XName"/> are
 /// included in the collection.
 /// </summary>
 /// <param name="elements"></param>
 /// <param name="name"></param>
 /// <param name="ignoreCase"></param>
 /// <returns></returns>
 public static IEnumerable <XAttribute> Attributes(this IEnumerable <XElement> elements, XName name, bool ignoreCase)
 {
     if (ignoreCase)
     {
         return(elements.Attributes().Where(p => p.Name.ToString().ToLower() == name.ToString().ToLower()));
     }
     else
     {
         return(elements.Attributes(name));
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Provides a case-insensitive comparison between an XName element and a string.
 /// </summary>
 /// <param name="xname">The XName to compare</param>
 /// <param name="name">The string to compare</param>
 /// <returns>Whether or not the XName and the string where the same (case-insensitive)</returns>
 public static bool Is(this XName xname, string name)
 {
     return(xname.ToString().Equals(name, StringComparison.OrdinalIgnoreCase));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Returns the <see cref="System.Xml.Linq.XAttribute"/> of this <see cref="System.Xml.Linq.XElement"/> that
 /// has the specified <see cref="System.Xml.Linq.XName"/>, optionally ignoring case.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="name"></param>
 /// <param name="ignoreCase"></param>
 /// <returns></returns>
 public static XAttribute Attribute(this XElement element, XName name, bool ignoreCase)
 {
     if (ignoreCase)
     {
         return(element.Attributes().Where(p => p.Name.ToString().ToLower() == name.ToString().ToLower()).FirstOrDefault());
     }
     else
     {
         return(element.Attribute(name));
     }
 }