Mega Code Archive

 
Categories / C# / Development Class
 

Get Xml value as Integer 64

using System; using System.Diagnostics; using System.Globalization; using System.IO; using System.Xml; using System.Xml.Linq; public static class XmlUtility {     public static long? GetValueAsInt64(this XAttribute attribute)     {         long result;         return (attribute != null) &&             long.TryParse(attribute.Value, out result) ?             result : (long?)null;     }     public static long? GetValueAsInt64(         this XAttribute attribute,         IFormatProvider formatProvider)     {         Debug.Assert(formatProvider != null, "formatProvider is null.");         long result;         return (attribute != null) &&             long.TryParse(attribute.Value,                 NumberStyles.Integer,                 formatProvider,                 out result) ?             result : (long?)null;     }     public static long? GetValueAsInt64(this XElement element)     {         long result;         return (element != null) &&             long.TryParse(element.Value, out result) ?             result : (long?)null;     }     public static long? GetValueAsInt64(         this XElement element,         IFormatProvider formatProvider)     {         Debug.Assert(formatProvider != null, "formatProvider is null.");         long result;         return (element != null) &&             long.TryParse(                 element.Value,                 NumberStyles.Integer,                 formatProvider,                 out result) ?             result : (long?)null;     } }