internal static async Task ComputeRefactoringAsync(RefactoringContext context, ExpressionSyntax expression) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); foreach (Diagnostic diagnostic in semanticModel.GetCompilerDiagnostics(expression.Span, context.CancellationToken)) { if (diagnostic.Id == CSharpErrorCodes.CannotImplicitlyConvertTypeExplicitConversionExists) { if (context.Span.IsEmpty || diagnostic.Location.SourceSpan == expression.Span) { expression = expression .Ancestors() .FirstOrDefault(f => f.Span == diagnostic.Location.SourceSpan) as ExpressionSyntax; if (expression != null && semanticModel.GetTypeSymbol(expression, context.CancellationToken)?.IsNullableOf(SpecialType.System_Boolean) == true) { if (semanticModel.GetTypeInfo(expression, context.CancellationToken).ConvertedType?.IsBoolean() == true || IsCondition(expression)) { RegisterRefactoring(context, expression); } } } } else if (diagnostic.Id == CSharpErrorCodes.OperatorCannotBeAppliedToOperands) { if (context.Span.IsEmpty || diagnostic.Location.SourceSpan == expression.Span) { var binaryExpression = expression .Ancestors() .FirstOrDefault(f => f.Span == diagnostic.Location.SourceSpan) as BinaryExpressionSyntax; if (binaryExpression != null) { ExpressionSyntax left = binaryExpression.Left; if (left.Span.Contains(context.Span)) { if (semanticModel.GetTypeSymbol(left, context.CancellationToken)?.IsNullableOf(SpecialType.System_Boolean) == true) { RegisterRefactoring(context, left); } } else { ExpressionSyntax right = binaryExpression.Right; if (right.Span.Contains(context.Span) && semanticModel.GetTypeSymbol(right, context.CancellationToken)?.IsNullableOf(SpecialType.System_Boolean) == true) { RegisterRefactoring(context, right); } } } } } } }