本文整理汇总了C#中BinaryOperatorType类的典型用法代码示例。如果您正苦于以下问题:C# BinaryOperatorType类的具体用法?C# BinaryOperatorType怎么用?C# BinaryOperatorType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryOperatorType类属于命名空间,在下文中一共展示了BinaryOperatorType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommutativeOperator
/// <summary>
/// Produces a choice pattern for <c>expr1 op expr2</c> or <c>expr2 op expr1</c>.
/// </summary>
public static Expression CommutativeOperator(Expression expr1, BinaryOperatorType op, Expression expr2)
{
return new Choice {
new BinaryOperatorExpression(expr1, op, expr2),
new BinaryOperatorExpression(expr2.Clone(), op, expr1.Clone())
};
}
示例2: BinaryExpression
public BinaryExpression(LexicalInfo lexicalInfoProvider, BinaryOperatorType operator_, Expression left, Expression right)
: base(lexicalInfoProvider)
{
this.Operator = operator_;
this.Left = left;
this.Right = right;
}
示例3: VBNetTestBinaryOperatorExpressionTest
void VBNetTestBinaryOperatorExpressionTest(string program, BinaryOperatorType op)
{
BinaryOperatorExpression boe = ParseUtil.ParseExpression<BinaryOperatorExpression>(program);
Assert.AreEqual(op, boe.Op);
Assert.IsTrue(boe.Left is SimpleNameExpression);
Assert.IsTrue(boe.Right is SimpleNameExpression);
}
示例4: NegateConditionOperator
/// <summary>
/// Get negation of the condition operator
/// </summary>
/// <returns>
/// negation of the specified condition operator, or BinaryOperatorType.Any if it's not a condition operator
/// </returns>
public static BinaryOperatorType NegateConditionOperator(BinaryOperatorType op)
{
switch (op) {
case BinaryOperatorType.ConditionalOr:
return BinaryOperatorType.ConditionalAnd;
case BinaryOperatorType.ConditionalAnd:
return BinaryOperatorType.ConditionalOr;
}
return BinaryOperatorType.Any;
}
示例5: BinaryOperatorResolveResult
public BinaryOperatorResolveResult(IType resultType, ResolveResult lhs, BinaryOperatorType op, ResolveResult rhs)
: base(resultType)
{
if (lhs == null)
throw new ArgumentNullException("lhs");
if (rhs == null)
throw new ArgumentNullException("rhs");
this.Left = lhs;
this.Operator = op;
this.Right = rhs;
}
示例6: Create
public static BinaryOperatorNode Create(BinaryOperatorType type, SubExpressionNode left, SubExpressionNode right, Token token, int tokenIndex)
{
switch (type)
{
case BinaryOperatorType.Ampersand:
return new AmpersandBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.AmpersandEqual:
return new AmpersandEqualBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.Caret:
return new CaretBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.CaretEqual:
return new CaretEqualBinaryOperaratorNode(left, right, token, tokenIndex);
case BinaryOperatorType.Divide:
return new DivideBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.DivideEqual:
return new DivideEqualBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.Minus:
return new MinusBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.MinusEqual:
return new MinusEqualBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.Mod:
return new ModBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.ModEqual:
return new ModEqualBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.Pipe:
return new PipeBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.PipeEqual:
return new PipeEqualBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.Plus:
return new PlusBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.PlusEqual:
return new PlusEqualBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.ShiftLeft:
return new ShiftLeftBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.ShiftLeftEqual:
return new ShiftLeftEqualBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.ShiftRight:
return new ShiftRightBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.ShiftRightEqual:
return new ShiftRightEqualBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.Star:
return new StarBinaryOperatorNode(left, right, token, tokenIndex);
case BinaryOperatorType.StarEqual:
return new StarEqualBinaryOperatorNode(left, right, token, tokenIndex);
default:
throw new InternalCompilerException("Unknown BinaryOperatorType.");
}
}
示例7: NegateRelationalOperator
/// <summary>
/// Get negation of the specified relational operator
/// </summary>
/// <returns>
/// negation of the specified relational operator, or BinaryOperatorType.Any if it's not a relational operator
/// </returns>
public static BinaryOperatorType NegateRelationalOperator (BinaryOperatorType op)
{
switch (op) {
case BinaryOperatorType.GreaterThan:
return BinaryOperatorType.LessThanOrEqual;
case BinaryOperatorType.GreaterThanOrEqual:
return BinaryOperatorType.LessThan;
case BinaryOperatorType.Equality:
return BinaryOperatorType.InEquality;
case BinaryOperatorType.InEquality:
return BinaryOperatorType.Equality;
case BinaryOperatorType.LessThan:
return BinaryOperatorType.GreaterThanOrEqual;
case BinaryOperatorType.LessThanOrEqual:
return BinaryOperatorType.GreaterThan;
}
return BinaryOperatorType.Any;
}
示例8: Process
private static string Process(BinaryOperatorType binaryOperatorType)
{
switch (binaryOperatorType)
{
case BinaryOperatorType.Equal:
return " = ";
case BinaryOperatorType.NotEqual:
return " != ";
case BinaryOperatorType.Greater:
return " > ";
case BinaryOperatorType.GreaterOrEqual:
return " >= ";
case BinaryOperatorType.Less:
return " < ";
case BinaryOperatorType.LessOrEqual:
return " <= ";
case BinaryOperatorType.Like:
return " LIKE ";
case BinaryOperatorType.Minus:
return " - ";
case BinaryOperatorType.Plus:
return " + ";
case BinaryOperatorType.Multiply:
return " * ";
case BinaryOperatorType.Divide:
return " / ";
default:
throw new NotSupportedException("Не поддерживаем BinaryOperatorType отличный от 'Equal', 'NotEqual', 'Greater', 'GreaterOrEqual', 'Less', 'LessOrEqual', 'Like', 'Minus', 'Plus', 'Multiply', 'Divide'. Переданное значение BinaryOperatorType: '{0}'".FillWith(binaryOperatorType));
}
}
示例9: SameOperatorPrecedenceTest
void SameOperatorPrecedenceTest(string firstOperator, BinaryOperatorType firstOperatorType,
string secondOperator, BinaryOperatorType secondOperatorType, bool vb)
{
string program = "a " + secondOperator + " b " + firstOperator + " c";
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program);
Assert.AreEqual(firstOperatorType, boe.Operator);
Assert.IsTrue(boe.Right is IdentifierExpression);
boe = (BinaryOperatorExpression)boe.Left;
Assert.AreEqual(secondOperatorType, boe.Operator);
Assert.IsTrue(boe.Left is IdentifierExpression);
Assert.IsTrue(boe.Right is IdentifierExpression);
program = "a " + firstOperator + " b " + secondOperator + " c";
boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program);
Assert.AreEqual(secondOperatorType, boe.Operator);
Assert.IsTrue(boe.Right is IdentifierExpression);
boe = (BinaryOperatorExpression)boe.Left;
Assert.AreEqual(firstOperatorType, boe.Operator);
Assert.IsTrue(boe.Left is IdentifierExpression);
Assert.IsTrue(boe.Right is IdentifierExpression);
}
示例10: BinaryOperator
public BinaryOperator(IElementCreationContext context, BinaryOperatorType defaultOperatorType)
: base(context, context.Owner.GetFloatType())
{
var services = new []
{
new BinaryOperatorService(BinaryOperatorType.Addition, "+", (a, b) => a + b),
new BinaryOperatorService(BinaryOperatorType.Subtraction, "-", (a, b) => a - b),
new BinaryOperatorService(BinaryOperatorType.Multiplication, "*", (a, b) => a * b),
new BinaryOperatorService(BinaryOperatorType.Division, "/", (a, b) => a / b),
new BinaryOperatorService(BinaryOperatorType.ShiftLeft, "<<", (a, b) => a << b),
new BinaryOperatorService(BinaryOperatorType.ShiftRight, ">>", (a, b) => a >> b),
new BinaryOperatorService(BinaryOperatorType.BitwiseAnd, "&", (a , b) => a & b),
new BinaryOperatorService(BinaryOperatorType.BitwiseOr, "|", (a , b) => a | b),
new BinaryOperatorService(BinaryOperatorType.Modulus, "%", (a , b) => a % b),
};
foreach (var service in services)
{
AddAction(new ElementAction(service.Text, () => OperatorType = service.Type));
}
_services = services.ToDictionary(s => s.Type, s => s);
ParameterA = context.Owner.CreateParameter("a", context.Owner.GetFloatType());
ParameterB = context.Owner.CreateParameter("b", context.Owner.GetFloatType());
Parameters.Add(ParameterA);
Parameters.Add(ParameterB);
Service = _services[BinaryOperatorType.Addition];
OperatorType = defaultOperatorType;
if (!string.IsNullOrWhiteSpace(context.Data))
{
var data = JsonConvert.DeserializeObject<BinaryOperatorData>(context.Data);
OperatorType = data.OperatorType;
}
}
示例11: OperatorPrecedenceTest
void OperatorPrecedenceTest(string strongOperator, BinaryOperatorType strongOperatorType,
string weakOperator, BinaryOperatorType weakOperatorType, bool vb)
{
string program = "a " + weakOperator + " b " + strongOperator + " c";
BinaryOperatorExpression boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program);
Assert.AreEqual(weakOperatorType, boe.Operator);
Assert.IsTrue(boe.Left is IdentifierExpression);
boe = (BinaryOperatorExpression)boe.Right;
Assert.AreEqual(strongOperatorType, boe.Operator);
Assert.IsTrue(boe.Left is IdentifierExpression);
Assert.IsTrue(boe.Right is IdentifierExpression);
program = "a " + strongOperator + " b " + weakOperator + " c";
boe = ParseUtilCSharp.ParseExpression<BinaryOperatorExpression>(program);
Assert.AreEqual(weakOperatorType, boe.Operator);
Assert.IsTrue(boe.Right is IdentifierExpression);
boe = (BinaryOperatorExpression)boe.Left;
Assert.AreEqual(strongOperatorType, boe.Operator);
Assert.IsTrue(boe.Left is IdentifierExpression);
Assert.IsTrue(boe.Right is IdentifierExpression);
}
示例12: BinaryOperatorExpression
public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right)
{
this.left = left;
this.op = op;
this.right = right;
}
示例13: GetOperatorPrecedence
static int GetOperatorPrecedence(Dictionary<BinaryOperatorType, int> dict, BinaryOperatorType op)
{
int p;
dict.TryGetValue(op, out p);
return p;
}
示例14: HandleEnumOperator
/// <summary>
/// Handle the following enum operators:
/// E operator +(E x, U y);
/// E operator +(U x, E y);
/// E operator –(E x, U y);
/// E operator &(E x, E y);
/// E operator |(E x, E y);
/// E operator ^(E x, E y);
/// </summary>
ResolveResult HandleEnumOperator(bool isNullable, IType enumType, BinaryOperatorType op, ResolveResult lhs, ResolveResult rhs)
{
// evaluate as (E)((U)x op (U)y)
if (lhs.IsCompileTimeConstant && rhs.IsCompileTimeConstant && !isNullable) {
IType elementType = GetEnumUnderlyingType(enumType);
lhs = ResolveCast(elementType, lhs);
if (lhs.IsError)
return lhs;
rhs = ResolveCast(elementType, rhs);
if (rhs.IsError)
return rhs;
return CheckErrorAndResolveCast(enumType, ResolveBinaryOperator(op, lhs, rhs));
}
IType resultType = MakeNullable(enumType, isNullable);
return BinaryOperatorResolveResult(resultType, lhs, op, rhs);
}
示例15: BinaryOperatorResolveResult
ResolveResult BinaryOperatorResolveResult(IType resultType, ResolveResult lhs, BinaryOperatorType op, ResolveResult rhs)
{
return new OperatorResolveResult(resultType, BinaryOperatorExpression.GetLinqNodeType(op, this.CheckForOverflow), lhs, rhs);
}