title: Generic string to enum conversion
body: <p>Suppose enum:</p>
  
  <pre><code>public enum SysLogsAppTypes { None, MonitorService, MonitorTool };
  </code></pre>
  
  <p>and here is a function to convert from the <code>ToString()</code> representation back to <code>enum</code>:  </p>
  
  <pre><code>private SysLogsAppTypes Str2SysLogsAppTypes(string str)  
  {  
      try  
      {  
          SysLogsAppTypes res = (SysLogsAppTypes)Enum
                                         .Parse(typeof(SysLogsAppTypes), str);  
          if (!Enum.IsDefined(typeof(SysLogsAppTypes), res)) 
              return SysLogsAppTypes.None;  
          return res;  
      }  
      catch  
      {  
      return SysLogsAppTypes.None;  
      }  
  }  
  </code></pre>
  
  <p>Is there a way to make this Generic ??</p>
  
  <p>I tried:</p>
  
  <pre><code>private T Str2enum&lt;T&gt;(string str)   
  {  
      try  
      {  
          T res = (T)Enum.Parse(typeof(T), str);  
          if (!Enum.IsDefined(typeof(T), res)) return T.None;  
          return res;  
      }  
      catch  
      {  
          return T.None;  
      }  
  }  
  </code></pre>
  
  <p>but I get:
  'T' is a 'type parameter', which is not valid in the given context<br>
  where there is T.None</p>
  
  <p>Any help ?
  Thanks  </p>