Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using CallerMemberName and MethodImplOptions.NoInlining - Is it necessary?

Quick background: Trying to create a method that will return a pre-defined string based on the method that calls it. (bit glossed over but near enough).

I am intending to use the [CallerMemberName] Attribute, but my question is:

=> Do I need to use the MethodImplOptions.NoInlining with this attribute, or is that implicitly applied by the compiler?

There are many examples of both the CallerMemberName attribute, and the older version for pre .net4.5 frameworks which use MethodImplOptions.NoInlining method attribute but nothing which explicitly say that you dont need to use them together?

Thanks in advance, and for reading!

like image 581
Chris Watts Avatar asked Nov 21 '25 05:11

Chris Watts


1 Answers

It's not necessary because CallerMemberName is resolved by compiler at compile time:

Caller Info values are emitted as literals into the Intermediate Language (IL) at compile time.

Inlining is done not by C# compiler but by JIT when compiling your IL code to assembly, so inlining cannot affect functionality provided by CallerMemberName.

like image 175
Evk Avatar answered Nov 22 '25 17:11

Evk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!