使用ModuleBuilder将类标记为“内部静态”

时间:2014-07-26 05:15:05

标签: c# .net class reflection static

我使用Reflection.Emit生成动态程序集,一切正常,但由于以下代码,生成的类标记为internal sealed

var typeBuilder = moduleBuilder.DefineType("MyNamespace.Program", TypeAttributes.Class | TypeAttributes.Sealed);

我没有看到任何提示TypeAttributes的{​​{1}}成员。它似乎不仅仅是编译器的便利性,因为我可以看到手动编写的类在反射器工具中显示为static

我怎样才能将自己的类型标记为静态?

1 个答案:

答案 0 :(得分:4)

使用它来工作:

var builderType = builderModule.DefineType("MyNamespace.Program", TypeAttributes.Class | TypeAttributes.NotPublic | TypeAttributes.Sealed | TypeAttributes.Abstract);

这给了internal static这就是我想要的。

相关问题