本文整理汇总了C#中BinaryExpressionSyntax类的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpressionSyntax类的具体用法?C# BinaryExpressionSyntax怎么用?C# BinaryExpressionSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BinaryExpressionSyntax类属于命名空间,在下文中一共展示了BinaryExpressionSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:ermau,项目名称:Instant,代码行数:26,代码来源:IdentifyingVisitor.cs
示例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);
}
}
开发者ID:Auxon,项目名称:Instant,代码行数:31,代码来源:LoggingRewriter.cs
示例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;
}
开发者ID:lawl-dev,项目名称:Kiwi,代码行数:7,代码来源:BoundBinaryExpression.cs
示例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;
}
开发者ID:pminiszewski,项目名称:HlslTools,代码行数:8,代码来源:BoundBinaryExpression.cs
示例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;
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:8,代码来源:ComputeExpressionCodeFixProvider.cs
示例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));
}
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:8,代码来源:StringConcatenationWithPlusCodeFixProvider.cs
示例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);
}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:12,代码来源:FormulaNormalizer.cs
示例13: ChangeOperator
private static BinaryExpressionSyntax ChangeOperator(BinaryExpressionSyntax binary)
{
return
SyntaxFactory.BinaryExpression(
OppositeExpressionKinds[binary.Kind()],
binary.Left,
binary.Right)
.WithTriviaFrom(binary);
}
开发者ID:Azzhag,项目名称:sonarlint-vs,代码行数:9,代码来源:BooleanCheckInvertedCodeFixProvider.cs
示例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));
}
}
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:9,代码来源:CSharpUseOrdinalStringComparison.cs
示例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);
}
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:9,代码来源:WriteBinaryExpression.cs
示例16: GetSimplifications
public static IEnumerable<ReplaceAction> GetSimplifications(BinaryExpressionSyntax b, ISemanticModel model, Assumptions assume, CancellationToken cancellationToken = default(CancellationToken))
{
if (!b.Left.DefinitelyHasBooleanType(model)) yield break;
if (!b.Right.DefinitelyHasBooleanType(model)) yield break;
// prep basic analysis
var leftEffects = b.Left.HasSideEffects(model, assume) != false;
var rightEffects = b.Right.HasSideEffects(model, assume) != false;
var lv = b.Left.TryGetConstBoolValue();
var rv = b.Right.TryGetConstBoolValue();
var cmp = b.Left.TryEvalAlternativeComparison(b.Right, model, assume);
// prep utility funcs for adding simplifications
var actions = new List<ReplaceAction>();
Action<String, ExpressionSyntax> include = (desc, rep) =>
actions.Add(new ReplaceAction(desc, b, rep));
Action<bool> useRight = v => {
if (!leftEffects)
include(v ? "rhs" : "!rhs", b.Right.MaybeInverted(!v));
};
Action<bool> useLeft = v => {
if (!rightEffects)
include(v ? "lhs" : "!lhs", b.Left.MaybeInverted(!v));
};
Action<bool> useBool = v => {
if (!leftEffects && !rightEffects) {
actions.Clear(); // override left/right
include(v + "", v.AsLiteral());
}
};
// try to simplify equality operators ==, !=, ^
bool? equality = null;
if (b.Kind == SyntaxKind.EqualsExpression) equality = true;
if (b.Kind == SyntaxKind.ExclusiveOrExpression || b.Kind == SyntaxKind.NotEqualsExpression) equality = false;
if (equality != null) {
if (lv != null) useRight(lv == equality);
if (rv != null) useLeft(rv == equality);
if (cmp != null) useBool(cmp == equality);
}
// try to simplify and/or operators &&, &, ||, |
var sticky = b.Kind.IsAndBL() ? false
: b.Kind.IsOrBL() ? true
: (bool?)null;
if (sticky != null) {
if (b.Kind.IsShortCircuitingLogic() && lv == sticky) rightEffects = false; // short-circuit prevents effects
if (cmp == true || lv == !sticky) useRight(true);
if (cmp == true || rv == !sticky) useLeft(true);
if (cmp == false || lv == sticky || rv == sticky) useBool(sticky.Value);
}
// expose simplifications as code issues/actions
foreach (var action in actions)
yield return action;
}
开发者ID:Strilanc,项目名称:Croslyn,代码行数:56,代码来源:ReducibleBooleanExpression.cs
示例17: VisitBinaryExpression
/// <summary>
/// Normalizes the <paramref name="binaryExpression" />.
/// </summary>
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax binaryExpression)
{
var expressionType = DetermineType(binaryExpression);
if (expressionType == ExpressionType.Other)
return base.VisitBinaryExpression(binaryExpression);
var left = ReplaceImplicitConversion(expressionType, binaryExpression.Left);
var right = ReplaceImplicitConversion(expressionType, binaryExpression.Right);
return binaryExpression.Update(left, binaryExpression.OperatorToken, right);
}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:13,代码来源:FormulaNormalizer.cs
示例18: GetTransformedDocumentAsync
private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, BinaryExpressionSyntax syntax)
{
var newNode = SyntaxFactory.ParenthesizedExpression(syntax.WithoutTrivia())
.WithTriviaFrom(syntax)
.WithoutFormatting();
var newSyntaxRoot = root.ReplaceNode(syntax, newNode);
return Task.FromResult(document.WithSyntaxRoot(newSyntaxRoot));
}
开发者ID:nukefusion,项目名称:StyleCopAnalyzers,代码行数:10,代码来源:SA1407SA1408CodeFixProvider.cs
示例19: CreateNestedIf
internal static SyntaxNode CreateNestedIf(BinaryExpressionSyntax condition, SyntaxNode root)
{
var ifStatement = condition.FirstAncestorOfType<IfStatementSyntax>();
var nestedIf = SyntaxFactory.IfStatement(condition.Right, ifStatement.Statement);
var newStatement = ifStatement.Statement.IsKind(SyntaxKind.Block) ? (StatementSyntax)SyntaxFactory.Block(nestedIf) : nestedIf;
var newIf = ifStatement.WithCondition(condition.Left)
.WithStatement(newStatement)
.WithAdditionalAnnotations(Formatter.Annotation);
var newRoot = root.ReplaceNode(ifStatement, newIf);
return newRoot;
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:11,代码来源:SplitIntoNestedIfCodeFixProvider.cs
示例20: IntegrateStringsAsync
private async Task<Document> IntegrateStringsAsync(Document document, BinaryExpressionSyntax addExpression, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var newExpression = ToIntegratedString(addExpression.Left, addExpression.Right);
var newRoot = root.ReplaceNode(addExpression, newExpression);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
开发者ID:miya2000,项目名称:StringIntegrationCodeRefactoring,代码行数:12,代码来源:StringIntegrationCodeRefactoringProvider.cs
注:本文中的BinaryExpressionSyntax类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论