Пример #1
0
 /// <summary>
 /// Gets the value of the attribute with the specified local name and namespace URI.
 /// </summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="xelem">The element to act on.</param>
 /// <param name="attrLocalName">Name of the attribute local.</param>
 /// <param name="ns">The namespace.</param>
 /// <param name="transformer">The transformer to/from T object.</param>
 /// <param name="defaultValue">The default value.</param>
 /// <returns>
 /// The attribute's value as a string.
 /// </returns>
 /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
 public static T Get <T>(this XElement xelem, string attrLocalName, XNamespace ns, IAttributeValueTransformer <T> transformer, T defaultValue)
 {
     if (transformer == null)
     {
         throw new ArgumentNullException(nameof(transformer));
     }
     return(xelem.HasAttribute(attrLocalName, ns) ? transformer.ConvertFrom(xelem.Get(attrLocalName, ns)) : defaultValue);
 }
Пример #2
0
 /// <summary>
 /// Gets the value of the attribute with the specified local name and <paramref name="xelem"/> namespace.
 /// </summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="xelem">The element to act on.</param>
 /// <param name="attrLocalName">Name of the attribute local.</param>
 /// <param name="transformer">The transformer to/from T object.</param>
 /// <returns>
 /// The attribute's value as a string.
 /// </returns>
 /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception>
 public static T Get <T>(this XElement xelem, string attrLocalName, IAttributeValueTransformer <T> transformer)
 {
     if (transformer == null)
     {
         throw new ArgumentNullException(nameof(transformer));
     }
     return(transformer.ConvertFrom(xelem.Get(attrLocalName)));
 }