提交 10029bee 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #18679 from CyrusNajmabadi/useThrowElseClause

Don't offer to convert an 'if' to a 'throw expressoin' if there is an 'else clause'
......@@ -358,6 +358,34 @@ internal class ParserSyntax
public interface ISyntax
{
}");
}
[WorkItem(18670, "https://github.com/dotnet/roslyn/issues/18670")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseThrowExpression)]
public async Task TestNotWithElseClause()
{
await TestMissingInRegularAndScriptAsync(
@"
using System;
class C
{
int? _x;
public C(int? x)
{
if (x == null)
{
[|throw|] new ArgumentNullException(nameof(x));
}
else
{
Console.WriteLine();
}
_x = x;
}
}");
}
}
......
......@@ -110,6 +110,12 @@ private void AnalyzeOperation(OperationAnalysisContext context, INamedTypeSymbol
return;
}
if (ifOperation.IfFalseStatement != null)
{
// Can't offer this if the 'if-statement' has an 'else-clause'.
return;
}
var containingBlock = GetOperation(
semanticModel, ifOperation.Syntax.Parent, cancellationToken) as IBlockStatement;
if (containingBlock == null)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册