Get As Date Time from XAttribute - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get As Date Time from XAttribute

Demo Code


using System.Xml.Linq;
using System;/*w ww .  j  a  v  a  2s  .c om*/

public class Main{
        #endregion

        #region GetAsDateTime Method
        public static DateTime GetAsDateTime(this XAttribute attr)
        {
            DateTime ret = default(DateTime);
            DateTime value = default(DateTime);

            if (attr != null && !string.IsNullOrEmpty(attr.Value))
            {
                if (DateTime.TryParse(attr.Value, out value))
                    ret = value;
            }

            return ret;
        }
}

Related Tutorials