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

Allow usage of nameof on parameters of methods from outside #771

Closed
Mafii opened this issue Jul 27, 2017 · 5 comments
Closed

Allow usage of nameof on parameters of methods from outside #771

Mafii opened this issue Jul 27, 2017 · 5 comments

Comments

@Mafii
Copy link

Mafii commented Jul 27, 2017

Consider the following method:

public void TestMethod(int someValue, double someOtherValue)
{
  // this works
  string name = nameof(someValue);
}

Now I would love to use nameof onto a parameter from outside the method.

I propose the following syntax.

public void AntherTestMethod()
{
  // I want THIS to work
  // if my methods are in the same class
  string nameOfParam1InTestMethod = nameof(TestMethod.someValue);
  // if they are in other classes, add the class name infront of it
  string nameOfAParamInAnotherClass = nameof(TheClass.TestMethod.someOtherValue);
}

If this is not clear enough, another idea would be ClassName.MethodName.params.paramName

So the params keyword to access the params of a method.


Where is this useful?

This would be especially useful in Web/using ASP.NET when you have to specify the name of a parameter of a method as a string. With this change I would be able to adress them in a compile time and refoctoring safe way. If the param name changes, I'll notice.

@tannergooding
Copy link
Member

I've found a few places where this would also be useful in doc comments.

@taori
Copy link

taori commented Jul 28, 2017

some discussion already happened here #373

@perholje
Copy link

perholje commented Aug 8, 2017

This would be great for unit testing methods throwing ArgumentExceptions.

@taori
Copy link

taori commented Aug 8, 2017

@Mafii would you mind closing this issue, since some discussion already happened at #373 ? Also some effort has gone into discussing overloads there. There's no point in duplicating issues i think.

@Mafii
Copy link
Author

Mafii commented Aug 8, 2017

@taori Totally agree, thanks for linking me the dupe.

@Mafii Mafii closed this as completed Aug 8, 2017
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

5 participants