本文整理汇总了C#中BinaryOperatorExpression类的典型用法代码示例。如果您正苦于以下问题:C# BinaryOperatorExpression类的具体用法?C# BinaryOperatorExpression怎么用?C# BinaryOperatorExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryOperatorExpression类属于命名空间,在下文中一共展示了BinaryOperatorExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitBinaryOperatorExpression
public override void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression)
{
base.VisitBinaryOperatorExpression (binaryOperatorExpression);
if (binaryOperatorExpression.Operator != BinaryOperatorType.Equality &&
binaryOperatorExpression.Operator != BinaryOperatorType.InEquality)
return;
string floatType;
if (IsNaN(binaryOperatorExpression.Left, out floatType)) {
AddIsNaNIssue (binaryOperatorExpression, binaryOperatorExpression.Right, floatType);
} else if (IsNaN (binaryOperatorExpression.Right, out floatType)) {
AddIsNaNIssue (binaryOperatorExpression, binaryOperatorExpression.Left, floatType);
} else if (IsFloatingPoint(binaryOperatorExpression.Left) || IsFloatingPoint(binaryOperatorExpression.Right)) {
if (IsConstantInfinity(binaryOperatorExpression.Left) || IsConstantInfinity(binaryOperatorExpression.Right))
return;
AddIssue (binaryOperatorExpression, ctx.TranslateString ("Compare a difference with EPSILON"),
script => {
// Math.Abs(diff) op EPSILON
var builder = ctx.CreateTypeSytemAstBuilder(binaryOperatorExpression);
var diff = new BinaryOperatorExpression (binaryOperatorExpression.Left.Clone (),
BinaryOperatorType.Subtract, binaryOperatorExpression.Right.Clone ());
var abs = builder.ConvertType(new TopLevelTypeName("System", "Math")).Invoke("Abs", diff);
var op = binaryOperatorExpression.Operator == BinaryOperatorType.Equality ?
BinaryOperatorType.LessThan : BinaryOperatorType.GreaterThan;
var epsilon = new IdentifierExpression ("EPSILON");
var compare = new BinaryOperatorExpression (abs, op, epsilon);
script.Replace (binaryOperatorExpression, compare);
script.Link (epsilon);
});
}
}
示例2: VisitBinaryOperatorExpression
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
{
if (binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalAnd)
UnlockWith(binaryOperatorExpression);
return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
}
示例3: VisitBinaryOperatorExpression
public override void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression)
{
bool forceSpaces = false;
switch (binaryOperatorExpression.Operator) {
case BinaryOperatorType.Equality:
case BinaryOperatorType.InEquality:
forceSpaces = policy.SpaceAroundEqualityOperator;
break;
case BinaryOperatorType.GreaterThan:
case BinaryOperatorType.GreaterThanOrEqual:
case BinaryOperatorType.LessThan:
case BinaryOperatorType.LessThanOrEqual:
forceSpaces = policy.SpaceAroundRelationalOperator;
break;
case BinaryOperatorType.ConditionalAnd:
case BinaryOperatorType.ConditionalOr:
forceSpaces = policy.SpaceAroundLogicalOperator;
break;
case BinaryOperatorType.BitwiseAnd:
case BinaryOperatorType.BitwiseOr:
case BinaryOperatorType.ExclusiveOr:
forceSpaces = policy.SpaceAroundBitwiseOperator;
break;
case BinaryOperatorType.Add:
case BinaryOperatorType.Subtract:
forceSpaces = policy.SpaceAroundAdditiveOperator;
break;
case BinaryOperatorType.Multiply:
case BinaryOperatorType.Divide:
case BinaryOperatorType.Modulus:
forceSpaces = policy.SpaceAroundMultiplicativeOperator;
break;
case BinaryOperatorType.ShiftLeft:
case BinaryOperatorType.ShiftRight:
forceSpaces = policy.SpaceAroundShiftOperator;
break;
case BinaryOperatorType.NullCoalescing:
forceSpaces = policy.SpaceAroundNullCoalescingOperator;
break;
}
var opToken = binaryOperatorExpression.OperatorToken;
if (opToken.PrevSibling != null && opToken.PrevSibling.Role != Roles.NewLine) {
ForceSpacesBefore(opToken, forceSpaces);
} else {
ForceSpacesAfter(binaryOperatorExpression.Left, false);
FixIndentation(opToken);
}
ForceSpacesAfter(opToken, opToken.NextSibling != null && opToken.NextSibling.Role != Roles.NewLine && forceSpaces);
binaryOperatorExpression.Left.AcceptVisitor(this);
// Handle line breaks in binary opeartor expression.
if (binaryOperatorExpression.Left.EndLocation.Line != binaryOperatorExpression.Right.StartLocation.Line) {
if (opToken.StartLocation.Line == binaryOperatorExpression.Right.StartLocation.Line) {
FixStatementIndentation(opToken.StartLocation);
} else {
FixStatementIndentation(binaryOperatorExpression.Right.StartLocation);
}
}
binaryOperatorExpression.Right.AcceptVisitor(this);
}
示例4: VisitAssignmentExpression
public override void VisitAssignmentExpression(AssignmentExpression expression)
{
base.VisitAssignmentExpression (expression);
Identifier identifier = expression.FindIdentifier();
if (identifier == null)
return;
switch (expression.Operator)
{
case AssignmentOperatorType.BitwiseOr:
case AssignmentOperatorType.BitwiseAnd:
case AssignmentOperatorType.ExclusiveOr:
case AssignmentOperatorType.Add:
case AssignmentOperatorType.Subtract:
case AssignmentOperatorType.Divide:
case AssignmentOperatorType.Modulus:
case AssignmentOperatorType.Multiply:
case AssignmentOperatorType.ShiftLeft:
case AssignmentOperatorType.ShiftRight:
{
BinaryOperatorType op = GetComplexAssignOperator (expression.Operator);
Expression right = new BinaryOperatorExpression (new IdentifierExpression (identifier.Name), op, expression.Right.Clone());
expression.Operator = AssignmentOperatorType.Assign;
expression.Right = GetAssignmentExpression (identifier, right);
break;
}
case AssignmentOperatorType.Assign:
expression.Right = GetAssignmentExpression (identifier, expression.Right);
break;
}
}
示例5: OrIsShortcircuit
public void OrIsShortcircuit()
{
IExpression trueexpr = new ConstantExpression(true);
IExpression dividebyzero = new BinaryOperatorExpression(new ConstantExpression(1), new ConstantExpression(0), BinaryOperator.Divide);
Assert.IsTrue((bool)(new BooleanExpression(trueexpr, dividebyzero, BooleanOperator.Or)).Evaluate(null));
}
示例6: AndIsShortcircuit
public void AndIsShortcircuit()
{
IExpression falseexpr = new ConstantExpression(false);
IExpression dividebyzero = new BinaryOperatorExpression(new ConstantExpression(1), new ConstantExpression(0), BinaryOperator.Divide);
Assert.IsFalse((bool)(new BooleanExpression(falseexpr, dividebyzero, BooleanOperator.And)).Evaluate(null));
}
示例7: GenerateTarget
Expression GenerateTarget(RefactoringContext context, BinaryOperatorExpression bOp)
{
var rr = context.Resolver.GetResolverStateBefore(bOp).LookupSimpleNameOrTypeName("Equals", emptyTypes, NameLookupMode.Expression) as MethodGroupResolveResult;
if (rr == null || rr.IsError || HasDifferentEqualsMethod (rr.Methods)) {
return new PrimitiveType ("object").Member("Equals");
}
return new IdentifierExpression("Equals");
}
示例8: EvaluateSubtractExpression
public void EvaluateSubtractExpression()
{
BinaryExpression expression = new BinaryOperatorExpression(new ConstantExpression(1), new ConstantExpression(2), BinaryOperator.Subtract);
Assert.IsNotNull(expression);
Assert.IsNotNull(expression.Left);
Assert.IsNotNull(expression.Right);
Assert.AreEqual(-1, expression.Evaluate(new BindingEnvironment()));
}
示例9: EvaluateMultiplyExpressionWithLeftString
public void EvaluateMultiplyExpressionWithLeftString()
{
BinaryExpression expression = new BinaryOperatorExpression(new ConstantExpression("spam"), new ConstantExpression(3), BinaryOperator.Multiply);
Assert.IsNotNull(expression);
Assert.IsNotNull(expression.Left);
Assert.IsNotNull(expression.Right);
Assert.AreEqual("spamspamspam", expression.Evaluate(new BindingEnvironment()));
}
示例10: EvaluateDivideToFloatExpression
public void EvaluateDivideToFloatExpression()
{
BinaryExpression expression = new BinaryOperatorExpression(new ConstantExpression(4), new ConstantExpression(5), BinaryOperator.Divide);
Assert.IsNotNull(expression);
Assert.IsNotNull(expression.Left);
Assert.IsNotNull(expression.Right);
Assert.AreEqual(0.8, expression.Evaluate(new BindingEnvironment()));
}
示例11: GetControlVariable
static VariableInitializer GetControlVariable(VariableDeclarationStatement variableDecl,
BinaryOperatorExpression condition)
{
var controlVariables = variableDecl.Variables.Where (
v =>
{
var identifier = new IdentifierExpression (v.Name);
return condition.Left.Match (identifier).Success ||
condition.Right.Match (identifier).Success;
}).ToList ();
return controlVariables.Count == 1 ? controlVariables [0] : null;
}
示例12: VisitBinaryOperatorExpression
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
{
bool leftdangerous = false;
bool rightdangerous = false;
if (binaryOperatorExpression.Operator == BinaryOperatorType.Equality)
{
if (binaryOperatorExpression.Left is PrimitiveExpression)
{
PrimitiveExpression prim = (PrimitiveExpression)binaryOperatorExpression.Left;
if (prim.Value.GetType() == typeof(double) ||
prim.Value.GetType() == typeof(float) ||
prim.Value.GetType() == typeof(decimal))
{
leftdangerous = true;
}
}
else if (binaryOperatorExpression.Left is IdentifierExpression)
{
IdentifierExpression idexpr = (IdentifierExpression)binaryOperatorExpression.Left;
if (doublefloatvariables.Contains(idexpr.Identifier))
{
leftdangerous = true;
}
}
if (binaryOperatorExpression.Right is PrimitiveExpression)
{
PrimitiveExpression prim = (PrimitiveExpression)binaryOperatorExpression.Right;
if (prim.Value.GetType() == typeof(double) ||
prim.Value.GetType() == typeof(float) ||
prim.Value.GetType() == typeof(decimal))
{
rightdangerous = true;
}
}
else if (binaryOperatorExpression.Right is IdentifierExpression)
{
IdentifierExpression idexpr = (IdentifierExpression)binaryOperatorExpression.Right;
if (doublefloatvariables.Contains(idexpr.Identifier))
{
rightdangerous = true;
}
}
if (leftdangerous || rightdangerous)
{
UnlockWith(binaryOperatorExpression);
}
}
return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
}
示例13: AddIsNaNIssue
void AddIsNaNIssue(BinaryOperatorExpression binaryOperatorExpr, Expression argExpr, string floatType)
{
if (ctx.Resolve (argExpr).Type.ReflectionName != "System.Single")
floatType = "double";
AddIssue (binaryOperatorExpr, string.Format(ctx.TranslateString ("Use {0}.IsNan()"), floatType),
script => {
Expression expr = new InvocationExpression (new MemberReferenceExpression (
new TypeReferenceExpression (new PrimitiveType (floatType)), "IsNaN"), argExpr.Clone ());
if (binaryOperatorExpr.Operator == BinaryOperatorType.InEquality)
expr = new UnaryOperatorExpression (UnaryOperatorType.Not, expr);
script.Replace (binaryOperatorExpr, expr);
});
}
示例14: GetRightSide
internal static Expression GetRightSide(BinaryOperatorExpression expression)
{
var parent = expression.Parent as BinaryOperatorExpression;
if (parent != null) {
if (parent.Left == expression) {
var parentClone = (BinaryOperatorExpression)parent.Clone();
parentClone.Left = expression.Right.Clone();
return parentClone;
}
}
return expression.Right.Clone();
}
示例15: CreateAndSplit
static CodeAction CreateAndSplit(RefactoringContext context, IfElseStatement ifStatement, BinaryOperatorExpression bOp)
{
return new CodeAction(
context.TranslateString("Split if"),
script => {
var nestedIf = (IfElseStatement)ifStatement.Clone();
nestedIf.Condition = GetRightSide(bOp);
script.Replace(ifStatement.Condition, GetLeftSide(bOp));
script.Replace(ifStatement.TrueStatement, new BlockStatement { nestedIf });
},
bOp.OperatorToken
);
}