本文整理汇总了C#中Operators.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Operators.ToString方法的具体用法?C# Operators.ToString怎么用?C# Operators.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Operators
的用法示例。
在下文中一共展示了Operators.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromOperator
public static string FromOperator(Operators op) {
switch(op) {
case Operators.Equals: return "Equal";
case Operators.NotEquals: return "NotEqual";
default:
return op.ToString();
}
}
示例2: OperatorToSymbol
// *** END GENERATED CODE ***
#endregion
public static SymbolId OperatorToSymbol(Operators op) {
switch (op) {
#region Generated OperatorToSymbol
// *** BEGIN GENERATED CODE ***
// generated by function: gen_OperatorToSymbol from: generate_ops.py
case Operators.Add: return Symbols.OperatorAdd;
case Operators.ReverseAdd: return Symbols.OperatorReverseAdd;
case Operators.InPlaceAdd: return Symbols.OperatorInPlaceAdd;
case Operators.Subtract: return Symbols.OperatorSubtract;
case Operators.ReverseSubtract: return Symbols.OperatorReverseSubtract;
case Operators.InPlaceSubtract: return Symbols.OperatorInPlaceSubtract;
case Operators.Power: return Symbols.OperatorPower;
case Operators.ReversePower: return Symbols.OperatorReversePower;
case Operators.InPlacePower: return Symbols.OperatorInPlacePower;
case Operators.Multiply: return Symbols.OperatorMultiply;
case Operators.ReverseMultiply: return Symbols.OperatorReverseMultiply;
case Operators.InPlaceMultiply: return Symbols.OperatorInPlaceMultiply;
case Operators.FloorDivide: return Symbols.OperatorFloorDivide;
case Operators.ReverseFloorDivide: return Symbols.OperatorReverseFloorDivide;
case Operators.InPlaceFloorDivide: return Symbols.OperatorInPlaceFloorDivide;
case Operators.Divide: return Symbols.OperatorDivide;
case Operators.ReverseDivide: return Symbols.OperatorReverseDivide;
case Operators.InPlaceDivide: return Symbols.OperatorInPlaceDivide;
case Operators.TrueDivide: return Symbols.OperatorTrueDivide;
case Operators.ReverseTrueDivide: return Symbols.OperatorReverseTrueDivide;
case Operators.InPlaceTrueDivide: return Symbols.OperatorInPlaceTrueDivide;
case Operators.Mod: return Symbols.OperatorMod;
case Operators.ReverseMod: return Symbols.OperatorReverseMod;
case Operators.InPlaceMod: return Symbols.OperatorInPlaceMod;
case Operators.LeftShift: return Symbols.OperatorLeftShift;
case Operators.ReverseLeftShift: return Symbols.OperatorReverseLeftShift;
case Operators.InPlaceLeftShift: return Symbols.OperatorInPlaceLeftShift;
case Operators.RightShift: return Symbols.OperatorRightShift;
case Operators.ReverseRightShift: return Symbols.OperatorReverseRightShift;
case Operators.InPlaceRightShift: return Symbols.OperatorInPlaceRightShift;
case Operators.BitwiseAnd: return Symbols.OperatorBitwiseAnd;
case Operators.ReverseBitwiseAnd: return Symbols.OperatorReverseBitwiseAnd;
case Operators.InPlaceBitwiseAnd: return Symbols.OperatorInPlaceBitwiseAnd;
case Operators.BitwiseOr: return Symbols.OperatorBitwiseOr;
case Operators.ReverseBitwiseOr: return Symbols.OperatorReverseBitwiseOr;
case Operators.InPlaceBitwiseOr: return Symbols.OperatorInPlaceBitwiseOr;
case Operators.ExclusiveOr: return Symbols.OperatorExclusiveOr;
case Operators.ReverseExclusiveOr: return Symbols.OperatorReverseExclusiveOr;
case Operators.InPlaceExclusiveOr: return Symbols.OperatorInPlaceExclusiveOr;
case Operators.LessThan: return Symbols.OperatorLessThan;
case Operators.GreaterThan: return Symbols.OperatorGreaterThan;
case Operators.LessThanOrEqual: return Symbols.OperatorLessThanOrEqual;
case Operators.GreaterThanOrEqual: return Symbols.OperatorGreaterThanOrEqual;
case Operators.Equals: return Symbols.OperatorEquals;
case Operators.NotEquals: return Symbols.OperatorNotEquals;
case Operators.LessThanGreaterThan: return Symbols.OperatorLessThanGreaterThan;
// *** END GENERATED CODE ***
#endregion
// unary operators
case Operators.OnesComplement: return Symbols.OperatorOnesComplement;
case Operators.Negate: return Symbols.OperatorNegate;
case Operators.Positive: return Symbols.Positive;
case Operators.AbsoluteValue: return Symbols.AbsoluteValue;
case Operators.DivMod: return Symbols.DivMod;
case Operators.ReverseDivMod: return Symbols.ReverseDivMod;
case Operators.Compare: return Symbols.Cmp;
default:
throw new InvalidOperationException(op.ToString());
}
}
示例3: OperatorToReversedSymbol
public static SymbolId OperatorToReversedSymbol(Operators op) {
switch(op){
#region Generated OperatorToReversedSymbol
// *** BEGIN GENERATED CODE ***
case Operators.Add: return Symbols.OperatorReverseAdd;
case Operators.Subtract: return Symbols.OperatorReverseSubtract;
case Operators.Power: return Symbols.OperatorReversePower;
case Operators.Multiply: return Symbols.OperatorReverseMultiply;
case Operators.FloorDivide: return Symbols.OperatorReverseFloorDivide;
case Operators.Divide: return Symbols.OperatorReverseDivide;
case Operators.TrueDivide: return Symbols.OperatorReverseTrueDivide;
case Operators.Mod: return Symbols.OperatorReverseMod;
case Operators.LeftShift: return Symbols.OperatorReverseLeftShift;
case Operators.RightShift: return Symbols.OperatorReverseRightShift;
case Operators.BitwiseAnd: return Symbols.OperatorReverseBitwiseAnd;
case Operators.BitwiseOr: return Symbols.OperatorReverseBitwiseOr;
case Operators.ExclusiveOr: return Symbols.OperatorReverseExclusiveOr;
case Operators.LessThan: return Symbols.OperatorGreaterThan;
case Operators.LessThanOrEqual: return Symbols.OperatorGreaterThanOrEqual;
case Operators.GreaterThan: return Symbols.OperatorLessThan;
case Operators.GreaterThanOrEqual: return Symbols.OperatorLessThanOrEqual;
case Operators.Equals: return Symbols.OperatorEquals;
case Operators.NotEquals: return Symbols.OperatorNotEquals;
// *** END GENERATED CODE ***
#endregion
case Operators.DivMod: return Symbols.ReverseDivMod;
case Operators.ReverseDivMod: return Symbols.DivMod;
default:
Operators rev = CompilerHelpers.OperatorToReverseOperator(op);
if (rev != Operators.None) {
return OperatorToSymbol(rev);
}
System.Diagnostics.Debug.Assert(false);
throw new InvalidOperationException(op.ToString() + " cannot be reversed");
}
}
示例4: Evaluate
public static Variable Evaluate(Context sender, Variable left, Operators op, Variable right)
{
var log = sender.Root.Log;
bool validating = sender.Root.Valid == BlockBase.Validation.Running;
object l = null, r;
// make sure variable is not null.
if (right == null)
{
log.Error(StringsScripting.Evaluate_null_variable);
return null;
}
r = right.Value;
if (op != Operators.Not) // "Not" doesn't use left variable.
{
if (left == null)
{
log.Error(StringsScripting.Evaluate_null_variable);
return null;
}
l = left.Value;
}
// allow equals to work on unset variables.
if (op == Operators.Equal)
{
if (l == null || r == null)
return new Variable(l == null && r == null);
}
// make sure variable is set.
if (!right.IsSet)
{
log.Error(string.Format(StringsScripting.Formatted_Evaluate_Operator_unset_variable, op.ToString())); // ToDo : Different error?
return null;
}
if (op != Operators.Not && op != Operators.Assign) // "Not" and "Assign" can use a unset left variable.
{
if (!left.IsSet)
{
log.Error(string.Format(StringsScripting.Formatted_Evaluate_Operator_unset_variable, op.ToString())); // ToDo : Different error?
return null;
}
}
// Do not allow assign to readonly variables.
if (op == Operators.Assign && left.Readonly)
{
log.Error(StringsScripting.Evaluate_Assign_Readonly);
return null;
}
// try to evaluate the viriable value directly.
if (l is IVType)
{
var results = ((IVType)l).Evaluate(sender, left, op, right);
if (results != null)
return results;
}
if (r is IVType)
{
var results = ((IVType)r).Evaluate(sender, left, op, right);
if (results != null)
return results;
}
switch (op)
{
// logic not
case Operators.Not:
object value = right.Value;
if (value is bool)
return new Variable(!(bool)value);
if (value is string)
return new Variable(Query.Not((string)value));
log.Error(string.Format(StringsScripting.Formatted_Evaluate_Operator_type_invalid, op.ToString(), "", value.GetType().Name));
return null;
// assign
case Operators.Assign:
if (left.IsSet)
{
if (l.GetType() == r.GetType())
{
if (!validating) // Don't change variable if we are validating.
left.Value = r;
}
else
{
log.Error(string.Format(StringsScripting.Formatted_Evaluate_Assign_type_mismatch, l.GetType().Name, r.GetType().Name));
return null;
}
}
else
{
if (validating)
left.Value = getDefault(right.Value.GetType());
//.........这里部分代码省略.........