title: GetMember vs GetField performance in C#
body: <p>Anybody know what the best to use to read a XmlEnumAttribute</p>
  
  <p>Option 1: With GetMember </p>
  
  <pre><code>    public static string XmlEnum(this Enum e)
      {
          Type type = e.GetType();
          MemberInfo[] memInfo = type.GetMember(e.ToString());
          if (memInfo != null &amp;&amp; memInfo.Length &gt; 0)
          {
              object[] attrs = memInfo[0].GetCustomAttributes(typeof(XmlEnumAttribute), false);
              if (attrs != null &amp;&amp; attrs.Length &gt; 0)
              {
                  return ((XmlEnumAttribute)attrs[0]).Name;
              }
          }
          return e.ToString();
      }
  </code></pre>
  
  <p>Option 2: With GetField</p>
  
  <pre><code>    public static string XmlEnum2(this Enum e)
      {
          Type type = e.GetType();
          FieldInfo info = type.GetField(e.ToString());
          if (!info.IsDefined(typeof(XmlEnumAttribute), false))
          {
              return e.ToString();
          }
          object[] attrs = info.GetCustomAttributes(typeof(XmlEnumAttribute), false);
          return ((XmlEnumAttribute)attrs[0]).Name;
      }
  </code></pre>