-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add support for top level statements #980
base: draft-v9
Are you sure you want to change the base?
Add support for top level statements #980
Conversation
} | ||
``` | ||
|
||
The class name `Program` shall be referenceable by name from within the application. However, the method name `«Main»` is used here for illustrative purposes only. The actual name generated by the implementation is unspecified, and cannot be referenced by name from within the application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this say that the generated name is readable via CallerMemberNameAttribute?
System.Console.WriteLine(WhoAmI()); // outputs "<Main>$"
System.Action action = () => System.Console.WriteLine(WhoAmI());
action(); // outputs "<Main>$" again, not the name of the method generated for the lambda
string WhoAmI(
[System.Runtime.CompilerServices.CallerMemberName]string member = null)
{
return member;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KalleOlaviNiemitalo, I confirm that the generated name can be found, but it's not clear to me how one might make use of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be best to add something about this to the specification of CallerMemberNameAttribute, to clarify that the name of the generated method is substituted even though it does not occur in the source code. Because this doesn't work like in lambda expressions where the user-specified name is used even though the code is generated to a differently-named method.
using System;
using System.Runtime.CompilerServices;
class C
{
void M(int i)
{
// calls N(i, "M") even though the call is in a method named something like <M>b__0
Action a = () => N(i);
}
static void N(int i, [CallerMemberName] string mem = null)
{
}
}
No description provided.