Hope I hadn't overseen the matching thread (found nothing about this topic in the docs)…
When using CallerMemberNameAttribute, is it assured by the framework that even if the method is inlined by the optimizing compiler, the member name is set to the caller, and not to the caller's caller?
Sample:
void MethodNeedsCallersName([CallerMemberName] caller = null) { Console.WriteLine(caller); } void CallerMethod() { MethodNeedsCallersName(); } void CallersCallerMethod() { CallerMethod(); }
In case MethodNeedsCallersName will be inlined by optimization, what will be the console output of MethodNeedsCallersName when CallersCallerMethod is invoked: "CallerMethod" or "CallersCallerMethod"?
Or should I always use [MethodImpl(MethodImplOptions.NoInlining)] on methods using the CallerMemberNameAttribute to make sure the correct name will be passed?
Thanks