My argument is that you should always use CallerMemberName in cases where you want to pass a member name as it prevents mistakes.
Really, the only scenario I could use it and don't is like this:
publicvoidLogSomething(stringmessage,[CallerMemberName]caller="")=>LogSomething(message,LogPriority.Normal,caller);publicvoidLogSomething(stringmessage,LogPrioritypriority,[CallerMemberName]caller=""){// Do some logging}
In this example, if I didn't pass in caller to the other method via the overload, caller would default to LogSomething.
So, really, that's the only case where I would explicitly set caller - when I need to pass data around and don't wantCallerMemberName to overwrite the value.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Loved the article!!
Didn't know about this feature until now. When should I use it instead of overload or just passing an nullable parameter?
My argument is that you should always use CallerMemberName in cases where you want to pass a member name as it prevents mistakes.
Really, the only scenario I could use it and don't is like this:
In this example, if I didn't pass in caller to the other method via the overload, caller would default to
LogSomething
.So, really, that's the only case where I would explicitly set
caller
- when I need to pass data around and don't wantCallerMemberName
to overwrite the value.