本文整理汇总了C#中BinaryOperatorExpression类的典型用法代码示例。如果您正苦于以下问题:C# BinaryOperatorExpression类的具体用法?C# BinaryOperatorExpression怎么用?C# BinaryOperatorExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BinaryOperatorExpression类属于命名空间,在下文中一共展示了BinaryOperatorExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
});
}
}
开发者ID:artifexor,项目名称:NRefactory,代码行数:32,代码来源:CompareFloatWithEqualityOperatorIssue.cs
示例2: VisitBinaryOperatorExpression
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
{
if (binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalAnd)
UnlockWith(binaryOperatorExpression);
return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
}
开发者ID:vlad2135,项目名称:strokes,代码行数:7,代码来源:OperatorAndAchievement.cs
示例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);
}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:60,代码来源:FormattingVisitor_Expressions.cs
示例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;
}
}
开发者ID:ermau,项目名称:Instant,代码行数:35,代码来源:InstrumentingRewriter.cs
示例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));
}
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:7,代码来源:BooleanExpressionTests.cs
示例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));
}
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:7,代码来源:BooleanExpressionTests.cs
示例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");
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:8,代码来源:ConvertEqualityOperatorToEqualsAction.cs
示例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()));
}
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:10,代码来源:BinaryOperatorExpressionTest.cs
示例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()));
}
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:10,代码来源:BinaryOperatorExpressionTest.cs
示例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()));
}
开发者ID:ajlopez,项目名称:PythonSharp,代码行数:10,代码来源:BinaryOperatorExpressionTest.cs
示例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;
}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:12,代码来源:ForControlVariableNotModifiedIssue.cs
示例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);
}
开发者ID:vlad2135,项目名称:strokes,代码行数:52,代码来源:DangerousEqualityCheckAchievement.cs
示例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);
});
}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:13,代码来源:CompareFloatWithEqualityOperatorIssue.cs
示例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();
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:13,代码来源:SplitIfAction.cs
示例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
);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:13,代码来源:SplitIfAction.cs
示例16: VisitConditionalExpression
public override void VisitConditionalExpression(ConditionalExpression conditionalExpression)
{
Match m = pattern.Match(conditionalExpression);
if (m.Success) {
var a = m.Get<Expression>("a").Single();
var other = m.Get<Expression>("other").Single();
AddIssue(conditionalExpression, ctx.TranslateString("Convert to '??' expression"), script => {
var expr = new BinaryOperatorExpression (a.Clone (), BinaryOperatorType.NullCoalescing, other.Clone ());
script.Replace (conditionalExpression, expr);
});
}
base.VisitConditionalExpression (conditionalExpression);
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:13,代码来源:ConditionalToNullCoalescingIssue.cs
示例17: VisitBinaryOperatorExpression
public override void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression)
{
base.VisitBinaryOperatorExpression(binaryOperatorExpression);
var left = binaryOperatorExpression.Left;
var right = binaryOperatorExpression.Right;
if (left is IdentifierExpression &&
right is IdentifierExpression)
{
var leftIdent = (left as IdentifierExpression).Identifier;
var rightIdent = (right as IdentifierExpression).Identifier;
if (leftIdent == rightIdent)
{
if (binaryOperatorExpression.Operator == BinaryOperatorType.Subtract)
{
binaryOperatorExpression.ReplaceWith(new PrimitiveExpression(0));
return;
}
}
}
if (right is PrimitiveExpression &&
(right as PrimitiveExpression).Value is int &&
(int)(right as PrimitiveExpression).Value == 0)
{
if (binaryOperatorExpression.Operator == BinaryOperatorType.Add ||
binaryOperatorExpression.Operator == BinaryOperatorType.Subtract)
{
binaryOperatorExpression.ReplaceWith(left);
return;
}
}
if (binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalAnd)
{
if (ReplaceConditionalAnd(binaryOperatorExpression, left, right) ||
ReplaceConditionalAnd(binaryOperatorExpression, right, left))
return;
}
if (binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalOr)
{
if (ReplaceConditionalOr(binaryOperatorExpression, left, right) ||
ReplaceConditionalOr(binaryOperatorExpression, right, left))
return;
}
}
开发者ID:TreeSeed,项目名称:Tychaia,代码行数:48,代码来源:SimplifyZeroAndConditionalExpressionsVisitor.cs
示例18: ResolveOperator
protected bool ResolveOperator(BinaryOperatorExpression binaryOperatorExpression, OperatorResolveResult orr)
{
var method = orr != null ? orr.UserDefinedOperatorMethod : null;
if (method != null)
{
var inline = this.Emitter.GetInline(method);
if (!string.IsNullOrWhiteSpace(inline))
{
new InlineArgumentsBlock(this.Emitter,
new ArgumentsInfo(this.Emitter, binaryOperatorExpression, orr, method), inline).Emit();
return true;
}
else if (!this.Emitter.Validator.IsIgnoreType(method.DeclaringTypeDefinition))
{
if (orr.IsLiftedOperator)
{
this.Write(Bridge.Translator.Emitter.ROOT + ".Nullable.lift(");
}
this.Write(BridgeTypes.ToJsName(method.DeclaringType, this.Emitter));
this.WriteDot();
this.Write(OverloadsCollection.Create(this.Emitter, method).GetOverloadName());
if (orr.IsLiftedOperator)
{
this.WriteComma();
}
else
{
this.WriteOpenParentheses();
}
new ExpressionListBlock(this.Emitter,
new Expression[] {binaryOperatorExpression.Left, binaryOperatorExpression.Right}, null).Emit();
this.WriteCloseParentheses();
return true;
}
}
return false;
}
开发者ID:TerribleDev,项目名称:Bridge,代码行数:45,代码来源:BinaryOperatorBlock.cs
示例19: CreateOrSplit
static CodeAction CreateOrSplit(RefactoringContext context, IfElseStatement ifStatement, BinaryOperatorExpression bOp)
{
return new CodeAction(
context.TranslateString("Split if"),
script => {
var newElse = (IfElseStatement)ifStatement.Clone();
newElse.Condition = GetRightSide(bOp);
var newIf = (IfElseStatement)ifStatement.Clone();
newIf.Condition = GetLeftSide(bOp);
newIf.FalseStatement = newElse;
script.Replace(ifStatement, newIf);
script.FormatText(newIf);
},
bOp.OperatorToken
);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:18,代码来源:SplitIfAction.cs
示例20: VisitBinaryOperatorExpression
// The following conversions are implemented:
// a == null -> a Is Nothing
// a != null -> a Is Not Nothing
// i++ / ++i as statement: convert to i += 1
// i-- / --i as statement: convert to i -= 1
// ForStatement -> ForNextStatement when for-loop is simple
// if (Event != null) Event(this, bla); -> RaiseEvent Event(this, bla)
// Casts to value types are marked as conversions
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
{
if (binaryOperatorExpression.Op == BinaryOperatorType.Equality || binaryOperatorExpression.Op == BinaryOperatorType.InEquality) {
if (IsNullLiteralExpression(binaryOperatorExpression.Left)) {
Expression tmp = binaryOperatorExpression.Left;
binaryOperatorExpression.Left = binaryOperatorExpression.Right;
binaryOperatorExpression.Right = tmp;
}
if (IsNullLiteralExpression(binaryOperatorExpression.Right)) {
if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) {
binaryOperatorExpression.Op = BinaryOperatorType.ReferenceEquality;
} else {
binaryOperatorExpression.Op = BinaryOperatorType.ReferenceInequality;
}
}
}
return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:27,代码来源:CSharpConstructsConvertVisitor.cs
注:本文中的BinaryOperatorExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论