public static T Get <T>(this XElement thisValue, [NotNull] string name, T defaultValue) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } if (!IsValid(thisValue) || !thisValue.HasAttributes) { return(defaultValue); } XAttribute attribute = thisValue.Attribute(name); return(attribute == null ? defaultValue : attribute.Get(defaultValue)); }
public static T Get <T>(this XElement thisValue, [NotNull] string localName, string namespaceUri, T defaultValue) { if (string.IsNullOrEmpty(namespaceUri)) { return(Get(thisValue, localName, defaultValue)); } if (string.IsNullOrEmpty(localName)) { throw new ArgumentNullException(nameof(localName)); } if (!IsValid(thisValue) || !thisValue.HasAttributes) { return(defaultValue); } XNamespace ns = namespaceUri; XAttribute attribute = thisValue.Attribute(ns + localName); return(attribute == null ? defaultValue : attribute.Get(defaultValue)); }