예제 #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);
        }