Get Enum Elem - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Get Enum Elem

Demo Code


using System.Xml.Linq;
using System;/*  www  .ja  v  a  2s .c  om*/

public class Main{
        public static TEnum GetEnumElem<TEnum>(this XElement elem, string name)
            where TEnum : struct
        {
            Enum.TryParse<TEnum>(elem.GetElemValue(name), out var v);
            return v;
        }
        public static string GetElemValue(this XElement elem, string elemName)
        {
            return elem.Element(elemName)?.Value;
        }
}

Related Tutorials