提交 8420474b 编写于 作者: C CyrusNajmabadi

Only allow dictionary initializers in C# 7 and up.

上级 8936726f
......@@ -77,6 +77,22 @@ void M()
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCollectionInitializer)]
public async Task TestIndexAccess1_NotInCSharp5()
{
await TestMissingAsync(
@"
using System.Collections.Generic;
class C
{
void M()
{
var c = [||]new List<int>();
c[1] = 2;
}
}", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp5));
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCollectionInitializer)]
public async Task TestComplexIndexAccess1()
{
......
......@@ -268,7 +268,7 @@ private void AddMatches(ArrayBuilder<TExpressionStatementSyntax> matches)
out SyntaxNode instance)
{
instance = null;
if (!_syntaxFacts.SupportsIndexingInitializer)
if (!_syntaxFacts.SupportsIndexingInitializer(statement.SyntaxTree.Options))
{
return false;
}
......
......@@ -30,7 +30,8 @@ private CSharpSyntaxFactsService()
public bool IsCaseSensitive => true;
public bool SupportsIndexingInitializer => true;
public bool SupportsIndexingInitializer(ParseOptions options)
=> ((CSharpParseOptions)options).LanguageVersion >= LanguageVersion.CSharp6;
public bool IsAwaitKeyword(SyntaxToken token)
{
......
......@@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.LanguageServices
internal interface ISyntaxFactsService : ILanguageService
{
bool IsCaseSensitive { get; }
bool SupportsIndexingInitializer { get; }
bool SupportsIndexingInitializer(ParseOptions options);
bool IsAwaitKeyword(SyntaxToken token);
bool IsIdentifier(SyntaxToken token);
......
......@@ -41,11 +41,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Public ReadOnly Property SupportsIndexingInitializer As Boolean Implements ISyntaxFactsService.SupportsIndexingInitializer
Get
Return False
End Get
End Property
Public Function SupportsIndexingInitializer(options As ParseOptions) As Boolean Implements ISyntaxFactsService.SupportsIndexingInitializer
Return False
End Function
Public Function IsAwaitKeyword(token As SyntaxToken) As Boolean Implements ISyntaxFactsService.IsAwaitKeyword
Return token.Kind = SyntaxKind.AwaitKeyword
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册