Reputation: 5146
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?
Here's some more info from experimentation:
HasThis
or Standard
seem to always produce methods that reflect to Standard
.HasThis
reflect to HasThis
and those generated with Standard
reflect to Standard|HasThis
.Standard|HasThis
.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
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