提交 cfb20c71 编写于 作者: C CyrusNajmabadi

Do not offer in C# 6.

上级 e05e8b7c
......@@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.UsePatternMatching;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
......@@ -10,7 +11,7 @@
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UsePatternMatching
{
public partial class CSharpIsAndCastCheckCodeRefactoringProviderTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
public partial class CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzerTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
=> (new CSharpIsAndCastCheckWithoutNameDiagnosticAnalyzer(), new CSharpIsAndCastCheckWithoutNameCodeFixProvider());
......@@ -27,7 +28,6 @@ bool M(object obj)
return [||]obj is TestFile && ((TestFile)obj).i > 0;
}
}",
@"class TestFile
{
int i;
......@@ -38,6 +38,20 @@ bool M(object obj)
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineTypeCheck)]
public async Task TestNotInCSharp6()
{
await TestMissingAsync(
@"class TestFile
{
int i;
bool M(object obj)
{
return [||]obj is TestFile && ((TestFile)obj).i > 0;
}
}", parameters: new TestParameters(parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp6)));
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineTypeCheck)]
public async Task TestExpressionBody()
{
......
......@@ -53,8 +53,16 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext context)
{
var cancellationToken = context.CancellationToken;
var semanticModel = context.SemanticModel;
var root = semanticModel.SyntaxTree.GetRoot(cancellationToken);
var syntaxTree = semanticModel.SyntaxTree;
// "x is Type y" is only available in C# 7.0 and above. Don't offer this refactoring
// in projects targetting a lesser version.
if (((CSharpParseOptions)syntaxTree.Options).LanguageVersion < LanguageVersion.CSharp7)
{
return;
}
var root = syntaxTree.GetRoot(cancellationToken);
var isExpression = (BinaryExpressionSyntax)context.Node;
var workspace = (context.Options as WorkspaceAnalyzerOptions)?.Services.Workspace;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册