c# - CSharp Enumerate through nullable Enums -


one piece of code worth thousand words...

public enum entest { a, b, c }  public void printenum<t>() {     foreach (var e in enum.getvalues(typeof(t)))     debug.writeline(e.tostring()); }  printenum<entest>(); printenum<entest?>();    // cause failure in enum.getvalues() 

the above simplified larger problem illustrate failure.

does know how can iterate through (or values inside) when passing me nullable enum?

thanks in advance.

how this?

public static void printenum<t>()         {             type t = typeof (t);             if (t.isgenerictype)             {                 //assume it's nullable enum                 t = typeof (t).generictypearguments[0];             }              foreach (var e in enum.getvalues(t))                 console.writeline(e.tostring());         } 

Comments

Popular posts from this blog

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

SQL Server - MyCTE query based on 24 hour period (next day) -

php - Using str_replace to translate a MySQL Table in html -