我正在搜索引用程序集并注意到一个奇怪的注释/片段:
// Attribute class used by the compiler to mark modules.
// If present, then debugging information for everything in the
// assembly was generated by the compiler, and will be preserved
// by the Runtime so that the debugger can provide full functionality
// in the case of JIT attach. If not present, then the compiler may
// or may not have included debugging information, and the Runtime
// won't preserve the debugging info, which will make debugging after
// a JIT attach difficult.
[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Module, AllowMultiple = false)]
[ComVisible(true)]
public sealed class DebuggableAttribute : Attribute
{
现在我跳到了AttributeTargets
,想知道C#/ .NET中的模块是什么。
[Flags]
[ComVisible(true)]
[__DynamicallyInvokable]
[Serializable]
public enum AttributeTargets
{
[__DynamicallyInvokable] Assembly = 1,
[__DynamicallyInvokable] Module = 2,
[__DynamicallyInvokable] Class = 4,
[__DynamicallyInvokable] Struct = 8,
[__DynamicallyInvokable] Enum = 16,
[__DynamicallyInvokable] Constructor = 32,
[__DynamicallyInvokable] Method = 64,
[__DynamicallyInvokable] Property = 128,
[__DynamicallyInvokable] Field = 256,
[__DynamicallyInvokable] Event = 512,
[__DynamicallyInvokable] Interface = 1024,
[__DynamicallyInvokable] Parameter = 2048,
[__DynamicallyInvokable] Delegate = 4096,
[__DynamicallyInvokable] ReturnValue = 8192,
[__DynamicallyInvokable] GenericParameter = 16384,
[__DynamicallyInvokable] All = GenericParameter | ReturnValue | Delegate | Parameter | Interface | Event | Field | Property | Method | Constructor | Enum | Struct | Class | Module | Assembly,
}
所以我的问题是 - 如何使用属性从C#代码中定位模块?
答案 0 :(得分:1)
使用module
限定符,例如:
[module: Debuggable(DebuggableAttribute.DebuggingModes.Default)]
可以放在任何名称空间/类声明之上的任何.cs文件中。
模块是类型的容器。大多数编译器(包括C#)每个组件发出一个模块。您可以在反汇编工具中查看模块级属性,例如ILSpy。
请注意,这与VB.NET模块不同,后者类似于C#静态类。