relatively_random
relatively_random

Reputation: 5146

Which CallingConventions to use with Reflection.Emit?

This introductory guide here says you can use CallingConventions.Standard for basically anything: https://www.codeproject.com/Articles/13337/Introduction-to-Creating-Dynamic-Types-with-Reflec

On the other hand, MSDN states this for CallingConventions.Standard:

Specifies the default calling convention as determined by the common language runtime. Use this calling convention for static methods. For instance or virtual methods use HasThis.

https://msdn.microsoft.com/en-us/library/system.reflection.callingconventions

So, I assume I should listen to MSDN and only use Standard for static methods. But how come it works for instance methods? What's the difference?

Edit:

Here's some more info from experimentation:

So the conclusion is I should probably always use Standard after all? Still don't see any difference, to be honest, since both ways work.

Upvotes: 1

Views: 206

Answers (1)

hoodaticus
hoodaticus

Reputation: 3880

Use Standard when defining a static method.

Use Standard | HasThis when defining an instance method.

Standard basically tells .NET to use CLR Fastcall, and HasThis tells the compiler to pass a hidden this* in the first parameter.

Upvotes: 1

Related Questions