-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Update (jcouv): speclet (https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/extended-nameof-scope.md)
it would be fairly amazing if nameof also worked for MethodName arguments.
I think i've talked about this 1-2 years ago and some aspnet member also chimed in and mentioned how this could be useful for magic EntityFramework where the appropriate name must be passed too for connection strings to work.
So essentially i would love it if, instead of strings, i could be typing this:
[AuthGrantFilter(
AppFunction = ApplicationFunctionTypes.ReadProjectStructure,
TopLevelProjectId = nameof(topLevelProjectId),
SiteId = nameof(siteId))]
[AuthDenyFilter(
Context = DenyContext.Site,
TopLevelProjectId = nameof(topLevelProjectId),
SiteId = nameof(siteId))]
or this
[AuthGrantFilter(AppFunction =
ApplicationFunctionTypes.ReadProjectStructure,
TopLevelProjectId = nameof(GetChildrenOf.topLevelProjectId),
SiteId = nameof(GetChildrenOf.siteId))]
[AuthDenyFilter(
Context = DenyContext.Site,
TopLevelProjectId = nameof(GetChildrenOf.topLevelProjectId),
SiteId = nameof(GetChildrenOf.siteId))]
Update (jcouv):
This proposal (in its most likely and straightforward design) would affect scoping rules and thus would introduce a breaking change. It is worth considering whether this breaking change is severe. Here's an example to illustrate the problem:
const int p = 3;
[Attribute(Property = p)] // currently binds to the constant, but the parameter `p` would be in scope after this proposal
void M(int p) { }
Some alternatives for LDM to consider:
- Change the scoping rules and take the breaking change
- Only affect the scoping rules for
nameof
- Allow
nameof
to reference parameters with the method name as a qualifier[Attr(nameof(M.p)] void M(int p) { }
LDM history: