Assembly.GetTypes()返回奇怪的类型名称,例如<> c> [英] Assembly.GetTypes() returns strange type names e.g. "<>c"
本文介绍了Assembly.GetTypes()返回奇怪的类型名称,例如<> c>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Assembly.GetTypes()
时,我得到的类型具有 Type.Name
的类型以<$ c开头$ c><&c; ... 。
When using Assembly.GetTypes()
I get types that have Type.Name
that begin with <>c....
.
如果这是匿名类型或其他类型,我尝试用google搜索。但是不能得到一个很好的答案。
I tried to google if this is anonymous types or something else. But cannot get a really good answer.
Type上是否有一个属性指示这些类型是什么?我不喜欢做 if(type.Name.StartsWith(<>))
Is there a property on Type that indicate what these types are? I do not like having to do if(type.Name.StartsWith("<>"))
推荐答案
这些是编译器生成的显示类。您可以通过查找 CompilerGeneratedAttribute
:
These are compiler generated display classes. You can distinguish them by looking for the CompilerGeneratedAttribute
:
var attr = Attribute.GetCustomAttribute(type, typeof(CompilerGeneratedAttribute));
这篇关于Assembly.GetTypes()返回奇怪的类型名称,例如<> c>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文