Casting XML element to int64. - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Casting XML element to int64.

Demo Code


using System.Xml.Linq;
using System;//from   w w w .j  a va 2 s.  c om

public class Main{
        /// <summary>
        /// Casting element to int64.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static Int64? CastElementToInt64(this XElement element, String key)
        {
            Int64 x; 
            if (element.Element(key) == null) { return null; }
            var xElement = element.Element(key);
            if (xElement != null && Int64.TryParse(xElement.Value, out x))
            {
                return x;
            }
            return null;
        }
}

Related Tutorials