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
Post a Comment