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

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

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -