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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -