headsling
headsling

Reputation: 623

How do I refer to the containing type in a method on a runtime built type?

I would like to include a Copy method on a runtime built type that takes it's own type as a parameter - i'm sure i'm missing something obvious but i don't see how to do this

TypeBuilder recordTypeBuilder = 
     moduleBuilder.DefineType("_" + tableSpec.Name + "Record", TypeAttributes.Sealed,);

recordTypeBuilder.DefineMethod( "CopyFrom", MethodAttributes.Public, null, new[] { typeof( ??? ) });

the ???'s are where i have a problem. i can't construct the type yet, as i haven't finished creating it!

any ideas?

regards,

Upvotes: 1

Views: 234

Answers (1)

dtb
dtb

Reputation: 217313

TypeBuilder inherits from System.Type and can be used in Reflection.Emit definitions before it has been actually created:

recordTypeBuilder.DefineMethod(
    "CopyFrom", MethodAttributes.Public, null, new Type[] { recordTypeBuilder });

Upvotes: 1

Related Questions