コード例 #1
0
ファイル: Xml.cs プロジェクト: spspaner/Olive
        /// <summary>
        /// Gets the value of an attribute or inner text of an element with the specified path. For example "Tree/Branch1/Branch2".
        /// </summary>
        public static T GetValue <T>(this XContainer parent, string path)
        {
            string value = null;

            var node = parent.FindNode(path);

            if (node is XElement)
            {
                value = (node as XElement).Value;
            }
            else if (node is XAttribute)
            {
                value = (node as XAttribute).Value;
            }
            else if (node != null)
            {
                throw new Exception("The provided path (" + path + ") points to an invalid Xml node (" + node.GetType() + ").");
            }

            if (value.IsEmpty())
            {
                return(default(T));
            }

            if (typeof(T) == typeof(string))
            {
                return((T)(object)value);
            }

            return(value.To <T>());
        }
コード例 #2
0
ファイル: Xml.cs プロジェクト: Mohsens22/Olive
 public static XObject GetNode(this XContainer parent, string path) => parent.FindNode(path);