Casting XML attribute to int64. - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Casting XML attribute to int64.

Demo Code


using System.Xml.Linq;
using System;//from   w  w  w .  j  av a  2 s  .  co m

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

Related Tutorials