Raheel Khan
Raheel Khan

Reputation: 14787

Marking a class as `internal static` using ModuleBuilder

I am generating a dynamic assembly using Reflection.Emit and everything works fine but the generated class is marked as internal sealed due to the following code:

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

I don't see any of the TypeAttributes members that would hint at static. It does not seem to be just a compiler convenience as I can see manually written classes show up as static in reflector tools.

How could I mark my own type as static?

Upvotes: 3

Views: 444

Answers (1)

Raheel Khan
Raheel Khan

Reputation: 14787

Got it to work using:

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

This gives internal static which is what I wanted.

Upvotes: 4

Related Questions