Get As Decimal from XAttribute - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get As Decimal from XAttribute

Demo Code


using System.Xml.Linq;
using System;//from   w w w  .ja  va2s.c o  m

public class Main{
        #endregion

        #region GetAsDecimal Method
        public static decimal GetAsDecimal(this XAttribute attr)
        {
            decimal ret = 0;
            decimal value = 0;

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

            return ret;
        }
}

Related Tutorials