public async Task <ExpressionSyntax> ConvertReferenceOrNothingComparisonOrNullAsync(VBSyntax.ExpressionSyntax exprNode, bool negateExpression = false) { if (!(exprNode is VBSyntax.BinaryExpressionSyntax node) || !node.IsKind(VBasic.SyntaxKind.IsExpression, VBasic.SyntaxKind.EqualsExpression, VBasic.SyntaxKind.IsNotExpression, VBasic.SyntaxKind.NotEqualsExpression)) { return(null); } var notted = node.IsKind(VBasic.SyntaxKind.IsNotExpression, VBasic.SyntaxKind.NotEqualsExpression) || negateExpression; var isReferenceComparison = node.IsKind(VBasic.SyntaxKind.IsExpression, VBasic.SyntaxKind.IsNotExpression); if (ArgComparedToNull(node) is {} vbOtherArg) { var csOtherArg = await ConvertIsOrIsNotExpressionArgAsync(vbOtherArg); return(notted ? CommonConversions.NotNothingComparison(csOtherArg, isReferenceComparison) : CommonConversions.NothingComparison(csOtherArg, isReferenceComparison)); } if (isReferenceComparison) { var lhs = await ConvertIsOrIsNotExpressionArgAsync(node.Left); var rhs = await ConvertIsOrIsNotExpressionArgAsync(node.Right); var equalityCheck = new KnownMethod(nameof(System), nameof(Object), nameof(object.ReferenceEquals)) .Invoke(_visualBasicEqualityComparison.ExtraUsingDirectives, ConvertTo(node.Left, lhs, SpecialType.System_Object), rhs); return(notted ? SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, equalityCheck) : equalityCheck); } return(null); }
public async Task <ExpressionSyntax> ConvertNothingComparisonOrNullAsync(VBSyntax.ExpressionSyntax exprNode, bool negateExpression = false) { if (!(exprNode is VBSyntax.BinaryExpressionSyntax node) || !node.IsKind(VBasic.SyntaxKind.IsExpression, VBasic.SyntaxKind.EqualsExpression, VBasic.SyntaxKind.IsNotExpression, VBasic.SyntaxKind.NotEqualsExpression)) { return(null); } ExpressionSyntax otherArgument; if (node.Left.IsKind(VBasic.SyntaxKind.NothingLiteralExpression)) { otherArgument = (ExpressionSyntax) await ConvertIsOrIsNotExpressionArgAsync(node.Right); } else if (node.Right.IsKind(VBasic.SyntaxKind.NothingLiteralExpression)) { otherArgument = (ExpressionSyntax) await ConvertIsOrIsNotExpressionArgAsync(node.Left); } else { return(null); } var isReference = node.IsKind(VBasic.SyntaxKind.IsExpression, VBasic.SyntaxKind.IsNotExpression); var notted = node.IsKind(VBasic.SyntaxKind.IsNotExpression, VBasic.SyntaxKind.NotEqualsExpression) || negateExpression; return(notted ? CommonConversions.NotNothingComparison(otherArgument, isReference) : CommonConversions.NothingComparison(otherArgument, isReference)); }