如何distingush从.NET用户类编译器生成的类编译器、用户、distingush、NET

2023-09-06 13:10:28 作者:终究走散了

我有一张code在我的计划是通过检查是否含有DisplayClass在它的类型名称区分编译器生成的类。 在阅读this回答,我想我需要一个更好的办法。如何distingush从用户类编译器生成的类在.NET?

I have a piece of code in my program that distinguishes compiler-generated classes by checking whether they contain "DisplayClass" in its type name. upon reading this answer, I think I need a better way. How to distingush compiler-generated classes from user classes in .NET?

推荐答案

检查类属性编译器生成来区别于其他编译器生成的类

Check classes for attribute CompilerGenerated to distinguish compiler generated classes from other

http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.compilergeneratedattribute.aspx

在反射那些的显示的类可以看出这样的:

In reflector those Display classes can be seen like this:

[CompilerGenerated]
private sealed class <>c__DisplayClass1
{..}
 
精彩推荐
图片推荐