我如何定位模块?
How can I target a module?
我在参考程序集中搜索了一下,发现一个奇怪的东西 comment/snippet:
// 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# 代码中定位一个带有属性的模块?
使用 module
限定符,例如:
[module: Debuggable(DebuggableAttribute.DebuggingModes.Default)]
可以放在任何 .cs 文件中任何 namespace/class 声明之上。
模块是类型的容器。大多数编译器(包括 C#)为每个程序集生成一个模块。可以在ILSpy等反汇编工具中查看模块级属性
请注意,这与 VB.NET 模块不同,后者类似于 C# 静态 class。
我在参考程序集中搜索了一下,发现一个奇怪的东西 comment/snippet:
// 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# 代码中定位一个带有属性的模块?
使用 module
限定符,例如:
[module: Debuggable(DebuggableAttribute.DebuggingModes.Default)]
可以放在任何 .cs 文件中任何 namespace/class 声明之上。
模块是类型的容器。大多数编译器(包括 C#)为每个程序集生成一个模块。可以在ILSpy等反汇编工具中查看模块级属性
请注意,这与 VB.NET 模块不同,后者类似于 C# 静态 class。