如何distingush从.NET用户类编译器生成的类 [英] How to distingush compiler-generated classes from user classes in .NET

查看:355
本文介绍了如何distingush从.NET用户类编译器生成的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张code在我的计划是通过检查是否含有DisplayClass在它的类型名称区分编译器生成的类。
在阅读<一个href="http://stackoverflow.com/questions/6402491/what-is-this-type-in-net-reflection/6403431#6403431">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

<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.compilergeneratedattribute.aspx">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
{..}

这篇关于如何distingush从.NET用户类编译器生成的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆