c# - Reflection and autogenerated types -
i have class single method uses "yield" return statement. nested type automatically created. using reflection binding flags set bindingflags.declaredonly
, output:
// public members class.
test.filesystemobject..ctor
test.filesystemobject.getfiles(directoryinfo directory)
test.filesystemobject.getfiles(string path)// auto generated nested class. test.filesystemobject+<getfiles>d__4..ctor test.filesystemobject+<getfiles>d__4.<>3__directory test.filesystemobject+<getfiles>d__4.<>4__this test.filesystemobject+<getfiles>d__4.<directories>5__7 test.filesystemobject+<getfiles>d__4.<files>5__8 test.filesystemobject+<getfiles>d__4.<fso>5__6 test.filesystemobject+<getfiles>d__4.<i>5__9 test.filesystemobject+<getfiles>d__4.<unprocessed>5__5 test.filesystemobject+<getfiles>d__4.directory
how can determine whether type returned assembly.gettypes(bindingsflags)
such auto generated type? i'm looking simple way exclude these.
you can test if type has [compilergenerated]
attribute:
if (type.getcustomattribute(typeof(compilergeneratedattribute), true) != null) { ... }
alternatively, can check if name contains characters wouldn't valid in user code.
Comments
Post a Comment