本文整理汇总了C#中BinaryExpressionSyntax类的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpressionSyntax类的具体用法?C# BinaryExpressionSyntax怎么用?C# BinaryExpressionSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BinaryExpressionSyntax类属于命名空间,在下文中一共展示了BinaryExpressionSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddIsNaNIssue
static CodeAction AddIsNaNIssue(Document document, SemanticModel semanticModel, SyntaxNode root, BinaryExpressionSyntax node, ExpressionSyntax argExpr, string floatType)
{
return CodeActionFactory.Create(node.Span, DiagnosticSeverity.Warning, string.Format(node.IsKind(SyntaxKind.EqualsExpression) ? "Replace with '{0}.IsNaN(...)' call" : "Replace with '!{0}.IsNaN(...)' call", floatType), token =>
{
SyntaxNode newRoot;
ExpressionSyntax expr;
var arguments = new SeparatedSyntaxList<ArgumentSyntax>();
arguments = arguments.Add(SyntaxFactory.Argument(argExpr));
expr = SyntaxFactory.InvocationExpression(
SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
SyntaxFactory.ParseExpression(floatType),
SyntaxFactory.IdentifierName("IsNaN")
),
SyntaxFactory.ArgumentList(
arguments
)
);
if (node.IsKind(SyntaxKind.NotEqualsExpression))
expr = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, expr);
expr = expr.WithAdditionalAnnotations(Formatter.Annotation);
newRoot = root.ReplaceNode((SyntaxNode)node, expr);
return Task.FromResult(document.WithSyntaxRoot(newRoot));
});
}
开发者ID:Kavignon,项目名称:RefactoringEssentials,代码行数:25,代码来源:CompareOfFloatsByEqualityOperatorCodeFixProvider.cs
示例2: GetOuterLeft
internal static ExpressionSyntax GetOuterLeft(BinaryExpressionSyntax bop)
{
var leftBop = bop.Left as BinaryExpressionSyntax;
if (leftBop != null && bop.OperatorToken.IsKind(leftBop.OperatorToken.Kind()))
return GetOuterLeft(leftBop);
return bop.Left;
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:7,代码来源:ReplaceWithOperatorAssignmentCodeRefactoringProvider.cs
示例3: VisitBinaryExpression
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
{
var based = base.VisitBinaryExpression (node);
if (node.Left.FindIdentifierName() == null)
return node;
switch (node.Kind)
{
case SyntaxKind.AddAssignExpression:
case SyntaxKind.OrAssignExpression:
case SyntaxKind.SubtractAssignExpression:
case SyntaxKind.MultiplyAssignExpression:
case SyntaxKind.DivideAssignExpression:
case SyntaxKind.ModuloAssignExpression:
case SyntaxKind.RightShiftAssignExpression:
case SyntaxKind.LeftShiftAssignExpression:
case SyntaxKind.AndAssignExpression:
case SyntaxKind.ExclusiveOrAssignExpression:
case SyntaxKind.AssignExpression:
return based.WithTrailingTrivia (based.GetTrailingTrivia().Prepend (GetIdComment()));
default:
return node;
}
}
示例4: VisitBinaryExpression
protected override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
{
var nameSyntax = FindIdentifierName (node.Left);
if (nameSyntax == null)
return base.VisitBinaryExpression (node);
switch (node.Kind)
{
case SyntaxKind.AddAssignExpression:
case SyntaxKind.OrAssignExpression:
case SyntaxKind.SubtractAssignExpression:
case SyntaxKind.MultiplyAssignExpression:
case SyntaxKind.DivideAssignExpression:
case SyntaxKind.ModuloAssignExpression:
case SyntaxKind.RightShiftAssignExpression:
case SyntaxKind.LeftShiftAssignExpression:
case SyntaxKind.AndAssignExpression:
case SyntaxKind.ExclusiveOrAssignExpression:
var token = Syntax.Token (GetComplexAssignOperator (node.Kind));
ExpressionSyntax expr = Syntax.ParseExpression (nameSyntax.PlainName + token + node.Right);
return node.Update (node.Left, AssignToken, GetLogExpression (nameSyntax.PlainName, expr));
case SyntaxKind.AssignExpression:
return node.Update (node.Left, node.OperatorToken, GetLogExpression (nameSyntax.PlainName, node.Right));
default:
return base.VisitBinaryExpression (node);
}
}
示例5: TryFlip
static bool TryFlip(BinaryExpressionSyntax expr, out SyntaxKind flippedKind, out string operatorText)
{
switch (expr.Kind())
{
case SyntaxKind.LessThanExpression:
flippedKind = SyntaxKind.GreaterThanExpression;
operatorText = ">";
return true;
case SyntaxKind.LessThanOrEqualExpression:
flippedKind = SyntaxKind.GreaterThanOrEqualExpression;
operatorText = ">=";
return true;
case SyntaxKind.GreaterThanExpression:
flippedKind = SyntaxKind.LessThanExpression;
operatorText = "<";
return true;
case SyntaxKind.GreaterThanOrEqualExpression:
flippedKind = SyntaxKind.LessThanOrEqualExpression;
operatorText = "<=";
return true;
}
flippedKind = SyntaxKind.None;
operatorText = null;
return false;
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:25,代码来源:FlipRelationalOperatorArgumentsCodeRefactoringProvider.cs
示例6: BoundBinaryExpression
public BoundBinaryExpression(BoundExpression left, BoundExpression right, BinaryOperators @operator, BinaryExpressionSyntax binaryExpressionSyntax, IType type)
: base(binaryExpressionSyntax, type)
{
Left = left;
Right = right;
Operator = @operator;
}
示例7: GenerateTarget
ExpressionSyntax GenerateTarget(SemanticModel model, BinaryExpressionSyntax node)
{
var symbols = model.LookupSymbols(node.SpanStart).OfType<IMethodSymbol>();
if (!symbols.Any() || HasDifferentEqualsMethod(symbols))
return SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ParseExpression("object"), SyntaxFactory.IdentifierName("Equals"));
else
return SyntaxFactory.IdentifierName("Equals");
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:8,代码来源:ConvertEqualityOperatorToEqualsCodeRefactoringProvider.cs
示例8: PerformAction
static Document PerformAction(Document document, SyntaxNode root, BinaryExpressionSyntax bop)
{
var nodeToReplace = bop.IsParentKind(SyntaxKind.ParenthesizedExpression) ? bop.Parent : bop;
var castExpr = (ExpressionSyntax)SyntaxFactory.CastExpression(bop.Right as TypeSyntax, CSharpUtil.AddParensIfRequired(bop.Left.WithoutLeadingTrivia().WithoutTrailingTrivia())).WithLeadingTrivia(bop.GetLeadingTrivia()).WithTrailingTrivia(bop.GetTrailingTrivia());
var newRoot = root.ReplaceNode((SyntaxNode)nodeToReplace, castExpr);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:8,代码来源:ReplaceSafeCastWithDirectCastCodeRefactoringProvider.cs
示例9: BoundBinaryExpression
public BoundBinaryExpression(BinaryExpressionSyntax syntax, BinaryOperatorKind operatorKind, BoundExpression left, BoundExpression right, TypeSymbol type)
: base(BoundNodeKind.BinaryExpression, syntax)
{
OperatorKind = operatorKind;
Left = left;
Right = right;
Type = type;
}
示例10: ComputeExpression
internal static SyntaxNode ComputeExpression(SyntaxNode nodeToReplace, BinaryExpressionSyntax expression, SyntaxNode root, SemanticModel semanticModel)
{
var result = semanticModel.GetConstantValue(expression);
if (!result.HasValue) return null;
var newExpression = SyntaxFactory.ParseExpression(System.Convert.ToString(result.Value, System.Globalization.CultureInfo.InvariantCulture));
var newRoot = root.ReplaceNode(nodeToReplace, newExpression);
return newRoot;
}
示例11: CalculateNewRoot
private static SyntaxNode CalculateNewRoot(SyntaxNode root, BinaryExpressionSyntax currentAsBinary)
{
return root.ReplaceNode(currentAsBinary,
SyntaxFactory.ConcatenateExpression(
currentAsBinary.Left,
SyntaxFactory.Token(SyntaxKind.AmpersandToken).WithTriviaFrom(currentAsBinary.OperatorToken),
currentAsBinary.Right));
}
示例12: VisitBinaryExpression
/// <summary>
/// Normalizes the <paramref name="binaryExpression" />.
/// </summary>
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax binaryExpression)
{
if (!IsFormulaType(binaryExpression))
return base.VisitBinaryExpression(binaryExpression);
var left = ReplaceImplicitConversion(binaryExpression.Left);
var right = ReplaceImplicitConversion(binaryExpression.Right);
return binaryExpression.Update(left, binaryExpression.OperatorToken, right);
}
示例13: ChangeOperator
private static BinaryExpressionSyntax ChangeOperator(BinaryExpressionSyntax binary)
{
return
SyntaxFactory.BinaryExpression(
OppositeExpressionKinds[binary.Kind()],
binary.Left,
binary.Right)
.WithTriviaFrom(binary);
}
示例14: AnalyzeBinaryExpression
private static void AnalyzeBinaryExpression(BinaryExpressionSyntax node, SemanticModel model, Action<Diagnostic> addDiagnostic)
{
var leftType = model.GetTypeInfo(node.Left).Type;
var rightType = model.GetTypeInfo(node.Right).Type;
if (leftType != null && rightType != null && leftType.SpecialType == SpecialType.System_String && rightType.SpecialType == SpecialType.System_String)
{
addDiagnostic(node.OperatorToken.GetLocation().CreateDiagnostic(Rule));
}
}
示例15: Go
public static void Go(OutputWriter writer, BinaryExpressionSyntax expression)
{
var leftExpression = expression.Left;
var rightExpression = expression.Right;
var operatorToken = expression.OperatorToken;
WriteIt(writer, operatorToken, rightExpression, leftExpression);
}