DEV Community

Discussion on: Caller Member Info, C#, and You

Collapse
 
seangwright profile image
Sean G. Wright

I've used this in the past for some internal infrastructure pieces... but the one thing I don't like about this attribute is that it requires you to add a parameter to a method that the caller should not use.

It's like I create an API and expose something that I don't want the caller to use.

public class Logger
{
    public void Log(string message, string doNotUseThisParameter);
}

This breaks several SOLID principles and is downright confusing for those not familiar with how the [CallerMemberName] attribute works.

So, I normally don't expose any infrastructure that uses it and I try to keep its use very limited.

That said, it can be useful, and I'm sure there are devs out there that will discover it through this post.

Thanks!