Version Used:
VS 16.3.4
struct S
{
readonly $$
}
No void keyword here. A readonly void method could still modify global state using the value of instance state, so still meaningful.
struct S
{
public $$ int X() => 1;
}
readonly presents here.
struct S
{
public int X
{
$$ get => 1;
}
}
No readonly here.
struct S
{
public int X
{
$$
}
}
No readonly here.
struct S
{
public int X
{
readonly $$
}
}
Recommending types instead of accessor keywords.
@dotnet/roslyn-compiler can you verify all of these locations so we can get them implemented?
I have done some investigation:
https://github.com/dotnet/roslyn/blob/97b75fcb5807881b0e768357b82c1a3476a3ec2c/src/Workspaces/CSharp/Portable/Utilities/SyntaxKindSet.cs#L24-L42
Should include ref keyword.
https://github.com/dotnet/roslyn/blob/97b75fcb5807881b0e768357b82c1a3476a3ec2c/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTokenExtensions.cs#L546-L551
Should think readonly a modifier.
https://github.com/dotnet/roslyn/blob/97b75fcb5807881b0e768357b82c1a3476a3ec2c/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs#L288-L289
Should be MemberDeclarationSyntax. BaseTypeDeclarationSyntax and ImcompleteMemberSyntax both derives from it.
https://github.com/dotnet/roslyn/blob/97b75fcb5807881b0e768357b82c1a3476a3ec2c/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs#L708-L709
Don't assume member declaration when seeing readonly.
The implementation in #25570 is rude. https://github.com/dotnet/roslyn/pull/25570/files#r175509814
After doing those, most tests are passing except these two:
https://github.com/dotnet/roslyn/blob/97b75fcb5807881b0e768357b82c1a3476a3ec2c/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests.cs#L2215-L2247
@RikkiGibson
can you verify all of these locations so we can get them implemented?
All of the locations mentioned by @huoyaoyuan look like valid places to recommend the keyword to me.
And there may be some clearification for readonly ref readonly. Quite confusing for ones haven't read changelog.