提交 4a1b805f 编写于 作者: C CyrusNajmabadi

Simplify check.

上级 f61d8c49
......@@ -116,12 +116,6 @@ private void AnalyzeOperation(OperationAnalysisContext context, INamedTypeSymbol
return;
}
if (!IsOnlyStatementOfIf(ifOperation, throwOperation))
{
// The if-statement can only have a single throw-statement in it.
return;
}
var containingBlock = GetOperation(
semanticModel, ifOperation.Syntax.Parent, cancellationToken) as IBlockStatement;
if (containingBlock == null)
......@@ -195,18 +189,6 @@ private void AnalyzeOperation(OperationAnalysisContext context, INamedTypeSymbol
}
}
private bool IsOnlyStatementOfIf(IIfStatement ifOperation, IThrowStatement throwStatement)
{
if (ifOperation.IfTrueStatement.Syntax == throwStatement.Syntax)
{
return true;
}
return ifOperation.IfTrueStatement is IBlockStatement block &&
block.Statements.Length == 1 &&
block.Statements[0].Syntax == throwStatement.Syntax;
}
protected abstract ISyntaxFactsService GetSyntaxFactsService();
protected abstract ISemanticFactsService GetSemanticFactsService();
......@@ -318,8 +300,15 @@ private bool IsNull(IOperation operation)
var containingOperation = GetOperation(
semanticModel, throwStatement.Parent, cancellationToken);
if (containingOperation?.Kind == OperationKind.BlockStatement)
if (containingOperation is IBlockStatement block)
{
if (block.Statements.Length != 1)
{
// If we are in a block, then the block must only contain
// the throw statement.
return null;
}
// C# may have an intermediary block between the throw-statement
// and the if-statement. Walk up one operation higher in that case.
containingOperation = GetOperation(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册