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

Discussion: extend the scope of parameter names to attributes #443

Closed
alrz opened this issue Apr 15, 2017 · 5 comments
Closed

Discussion: extend the scope of parameter names to attributes #443

alrz opened this issue Apr 15, 2017 · 5 comments

Comments

@alrz
Copy link
Member

alrz commented Apr 15, 2017

[SomeAttribute(nameof(param))]
void M(object param, [CallerArgumentExpression(nameof(param))] string arg = null) {}

PS: This is different from #373 as it proposes to allow parameters in nameof from any method.

@gafter
Copy link
Member

gafter commented Apr 17, 2017

This would be an incompatible change. Instead of binding to a constant from the enclosing scope, an attribute argument would now bind to a (non-constant) parameter, which would make a currently compiling program an error.

@jamesqo
Copy link
Contributor

jamesqo commented May 15, 2017

@gafter Do you mean something like

private const string foo = "";

void M(string foo, [AttributeAcceptingString(foo)] string blah) {}

would break, because it would bind to the parameter foo instead of the constant foo? In that case, why not check to see if there is a constant named foo before checking for parameters?

@alrz
Copy link
Member Author

alrz commented May 15, 2017

@jamesqo this change would not affect your example, because foo as a parameter has no meaning in an attribute. However, it affects a nameof(constant) if there is also a parameter named constant, with no observable difference (it's the string "constant" either way). Anywho, as you said, with a specific lookup order this issue will be resolved.

@taori
Copy link

taori commented Jul 28, 2017

Accessing the name of argument names with this version is very inconvenient in comparison to a modification of the nameof expression as described in #373 i would say. (though bringing it in scope in gernal certainly would not hurt)

@alrz
Copy link
Member Author

alrz commented Jan 7, 2020

Closing in favor of championed issue #373

@alrz alrz closed this as completed Jan 7, 2020
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

4 participants