/// <summary> /// Searches a <see cref="XContainer" /> for the first <see cref="XElement" /> instance with the specified /// specified <see cref="XName" /> and then parses and returns its value as /// a value of type <typeparamref name="TValue"/>. /// </summary> /// <typeparam name="TValue">The type being parsed.</typeparam> /// <param name="container">The <see cref="XContainer" /></param> /// <param name="name">The attribute <see cref="XName" />.</param> /// <param name="def">The default enumeration value.</param> /// <returns>The value loaded from the configuration or the default value.</returns> public static TValue ParseCustomElement <TValue>(this XContainer container, XName name, TValue def) where TValue : IParseable, new() { var element = container.Element(name); var value = element != null ? element.Value : null; return(Serialize.ParseCustom <TValue>(value, def)); }
/// <summary> /// Searches a <see cref="XElement" /> for the first attribute instance with the specified /// specified <see cref="XName" /> and then parses and returns its value as /// a value of type <typeparamref name="TValue"/>. /// </summary> /// <typeparam name="TValue">The type being parsed.</typeparam> /// <param name="element">The <see cref="XElement" /></param> /// <param name="name">The attribute <see cref="XName" />.</param> /// <param name="def">The default enumeration value.</param> /// <returns>The value loaded from the configuration or the default value.</returns> public static TValue ParseCustomAttribute <TValue>(this XElement element, XName name, TValue def) where TValue : IParseable, new() { var attribute = element.Attribute(name); var value = attribute != null ? attribute.Value : null; return(Serialize.ParseCustom <TValue>(value, def)); }