Get As Boolean from XAttribute - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get As Boolean from XAttribute

Demo Code


using System.Xml.Linq;
using System;/*from w w  w  .j a  v  a  2  s.com*/

public class Main{
        #endregion

        #region GetAsBoolean Method
        public static bool GetAsBoolean(this XAttribute attr)
        {
            bool ret = false;
            bool value = false;

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

            return ret;
        }
}

Related Tutorials