Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require nameof()? #2358

Closed
GregReddick opened this issue May 23, 2017 · 1 comment
Closed

Require nameof()? #2358

GregReddick opened this issue May 23, 2017 · 1 comment

Comments

@GregReddick
Copy link

GregReddick commented May 23, 2017

I have the following older code:

if (arg == null)
{
    throw new ArgumentNullException("arg");
}

It would be nice to have some rule that would complain about arg and instead require:

if (arg == null)
{
    throw new ArgumentNullException(nameof(arg));
}

Using nameof() would be required on ArgumentException and things that inherit from it, such as ArgumentNullException, on any parameter where the parameter is named paramName.

This is a C# 6 feature, of course, so warnings and code fixes would only be applicable on projects using 6 or later. Thoughts?

@bjornhellander
Copy link
Contributor

Duplicate of #865.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants