Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }