Mega Code Archive

 
Categories / C# / XML
 

Get Xml value as TimeSpan

using System; using System.Diagnostics; using System.Globalization; using System.IO; using System.Xml; using System.Xml.Linq; public static class XmlUtility {     public static TimeSpan? GetValueAsTimeSpan(this XAttribute attribute)     {         TimeSpan result;         return (TimeSpan.TryParse(attribute.GetValue(), out result)) ? result : (TimeSpan?)null;     }     public static TimeSpan? GetValueAsTimeSpan(this XElement element)     {         TimeSpan t;         return (element != null) &&             TimeSpan.TryParse(element.Value, out t) ?             t : (TimeSpan?)null;     } }