コード例 #1
0
        public static string ReadStringAttribute(this XElement element, string attributeName, AttributeReadType readType = AttributeReadType.Mandatory)
        {
            if (element == null)
            {
                if (readType == AttributeReadType.Mandatory)
                {
                    throw new ArgumentNullException("element");    
                }

                return string.Empty;
            }

            var attribute = element.Attribute(attributeName);

            if (attribute == null)
            {
                if (readType == AttributeReadType.Mandatory)
                {
                    throw new NullReferenceException(string.Format("Attribute {0} is null.", attributeName));
                }

                return string.Empty;
            }

            return attribute.Value;
        }
コード例 #2
0
        public static bool? ReadBooleanAttribute(this XElement element, string attributeName, AttributeReadType readType = AttributeReadType.Mandatory)
        {
            var stringVal = element.ReadStringAttribute(attributeName, readType);
            if (string.IsNullOrEmpty(stringVal) && readType == AttributeReadType.Optional)
            {
                return null;
            }

            return Convert.ToBoolean(stringVal);
        }
コード例 #3
0
        public static List<string> ReadStringListAttribute(this XElement element, string attributeName, AttributeReadType readType = AttributeReadType.Mandatory)
        {
            var stringVal = element.ReadStringAttribute(attributeName, readType);
            if (string.IsNullOrEmpty(stringVal) && readType == AttributeReadType.Optional)
            {
                return null;
            }

            var result = stringVal.Split(',').Select(r => r.Trim()).Distinct().ToList();
            return result;
        }
コード例 #4
0
        public static List <string> ReadStringListAttribute(this XElement element, string attributeName, AttributeReadType readType = AttributeReadType.Mandatory)
        {
            var stringVal = element.ReadStringAttribute(attributeName, readType);

            if (string.IsNullOrEmpty(stringVal) && readType == AttributeReadType.Optional)
            {
                return(null);
            }

            var result = stringVal.Split(',').Select(r => r.Trim()).Distinct().ToList();

            return(result);
        }
コード例 #5
0
        public static bool?ReadBooleanAttribute(this XElement element, string attributeName, AttributeReadType readType = AttributeReadType.Mandatory)
        {
            var stringVal = element.ReadStringAttribute(attributeName, readType);

            if (string.IsNullOrEmpty(stringVal) && readType == AttributeReadType.Optional)
            {
                return(null);
            }

            return(Convert.ToBoolean(stringVal));
        }
コード例 #6
0
        public static string ReadStringAttribute(this XElement element, string attributeName, AttributeReadType readType = AttributeReadType.Mandatory)
        {
            if (element == null)
            {
                if (readType == AttributeReadType.Mandatory)
                {
                    throw new ArgumentNullException("element");
                }

                return(string.Empty);
            }

            var attribute = element.Attribute(attributeName);

            if (attribute == null)
            {
                if (readType == AttributeReadType.Mandatory)
                {
                    throw new NullReferenceException(string.Format("Attribute {0} is null.", attributeName));
                }

                return(string.Empty);
            }

            return(attribute.Value);
        }