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

asp.net mvc - Cannot display error message on Editor or EditorFor -

Reliable way to get Windows Version from registry -

python - No exponential form of the z-axis in matplotlib-3D-plots -