本文整理汇总了C#中IExpression.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# IExpression.Evaluate方法的具体用法?C# IExpression.Evaluate怎么用?C# IExpression.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IExpression
的用法示例。
在下文中一共展示了IExpression.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsBoolean
public static Boolean? AsBoolean(Object state, IExpression expression, Boolean? failover)
{
if (expression == null || expression.IsValid == false) return failover;
Number[] result = expression.Evaluate(state);
return (result.Length > 0) ? result[0].BooleanValue : failover;
}
示例2: Evaluate
protected override object Evaluate(IExpression left, IExpression right, ExecutionState state)
{
object b = TokenParser.VerifyUnderlyingType(right.Evaluate(state, token));
object a = TokenParser.VerifyUnderlyingType(left.Evaluate(state, token));
decimal x, y;
//typeof(decimal).IsAssignableFrom(typeof(a))
if (a is decimal)
x = (decimal)a;
else
{
//if(a is int || a is long || a is double || a is float || a is short
TypeConverter tc = TypeDescriptor.GetConverter(a);
if (!tc.CanConvertTo(typeof(decimal)))
return string.Concat(a, b);
x = (decimal)tc.ConvertTo(a, typeof(decimal));
}
if (b is decimal)
y = (decimal)b;
else
{
TypeConverter tc = TypeDescriptor.GetConverter(b);
if (!tc.CanConvertTo(typeof(decimal)))
return string.Concat(a, b);
y = (decimal)tc.ConvertTo(b, typeof(decimal));
}
return x + y;
}
示例3: AsSingle
public static Single? AsSingle(Object state, IExpression expression, Single? failover)
{
if (expression == null || expression.IsValid == false) return failover;
Number[] result = expression.Evaluate(state);
return (result.Length > 0) ? result[0].FloatValue : failover;
}
示例4: AsInt32
public static Int32 AsInt32(Object state, IExpression expression, Int32 failover)
{
if (expression == null || expression.IsValid == false) return failover;
Number[] result = expression.Evaluate(state);
return (result.Length > 0) ? result[0].IntValue : failover;
}
示例5: ResolveToObject
public static object ResolveToObject(IExpression expression, IContext context)
{
if (expression is VariableExpression)
return ResolveToObject((VariableExpression)expression, context);
if (expression is DotExpression)
return ResolveToObject((DotExpression)expression, context);
return expression.Evaluate(context);
}
示例6: ResolveToDictionary
public static IDictionary ResolveToDictionary(IExpression expression, IContext context)
{
if (expression is VariableExpression)
return ResolveToDictionary((VariableExpression)expression, context);
if (expression is DotExpression)
return ResolveToDictionary((DotExpression)expression, context);
return (IDictionary)expression.Evaluate(context);
}
示例7: Evaluate
public object Evaluate(IExpression expression)
{
this.machine.SetCurrent();
object result = expression.Evaluate(this.machine.Environment);
if (!(result is MarshalByRefObject))
return result;
return this.host.ResultToObject(result);
}
示例8: ResolveToObject
public static object ResolveToObject(IExpression expression, IBindingEnvironment environment)
{
if (expression is VariableExpression)
return ResolveToObject((VariableExpression)expression, environment);
if (expression is DotExpression)
return ResolveToObject((DotExpression)expression, environment);
return expression.Evaluate(environment);
}
示例9: ResolveToDictionary
public static IDictionary ResolveToDictionary(IExpression expression, IBindingEnvironment environment)
{
if (expression is VariableExpression)
return ResolveToDictionary((VariableExpression)expression, environment);
if (expression is DotExpression)
return ResolveToDictionary((DotExpression)expression, environment);
return (IDictionary)expression.Evaluate(environment);
}
示例10: AsPoint
public static Point? AsPoint(Object state, IExpression expression, Point? failover)
{
if (expression == null || expression.IsValid == false) return failover;
Number[] result = expression.Evaluate(state);
if (result.Length > 0 && result[0].NumberType != NumberType.None)
{
if (result.Length > 1 && result[1].NumberType != NumberType.None)
{
return new Point(result[0].IntValue, result[1].IntValue);
}
else
{
return new Point(result[0].IntValue, 0);
}
}
return failover;
}
示例11: Evaluate
public object Evaluate(IExpression expression)
{
if (expression == null)
return null;
Machine current = Machine.Current;
object result = null;
try
{
this.machine.SetCurrent();
result = expression.Evaluate(this.machine.Environment);
}
finally
{
Machine.SetCurrent(current);
}
return result;
}
示例12: Evaluate
public Value Evaluate(IExpression left, IExpression right, Scope scope)
{
Value l = left.Evaluate(scope);
Value r = right.Evaluate(scope);
if (l.Count > 1 && l.Count == r.Count)
{
var lv = new List<Value>(l.Enumerate());
var rv = new List<Value>(r.Enumerate());
var res = new List<Value>(lv.Count);
for (int i = 0; i < lv.Count(); i++)
res.Add(Evaluate(lv[i], rv[i], scope));
return new GTTree(res);
}
if (l.Count > 1 && r.Count == 1)
return new GTTree(from x in l.Enumerate()
select Evaluate(x, r, scope));
if (r.Count > 1 && l.Count == 1)
return new GTTree(from x in r.Enumerate()
select Evaluate(l, x, scope));
if (l is IGTAdapter && r is IGTAdapter)
{
dynamic res = Fun.Invoke(((IGTAdapter)l).Get(), ((IGTAdapter)r).Get());
if (l.Type == GTType.Float || r.Type == GTType.Float)
return new GTFloat(res);
else
return new GTInt(res);
}
throw new InvalidOperationException(String.Format("Cannot use operator {0} on types {1} and {2}", this, l.Type, r.Type));
}
示例13: Evaluate
protected override object Evaluate(IExpression left, IExpression right, ExecutionState state)
{
object b = right.Evaluate(state);
object a = left.Evaluate(state);
return !(a.Equals(b) || b.Equals(a)); // we check both sides in case one side has overridden the Equals method
}
示例14: Evaluate
protected override object Evaluate(IExpression left, IExpression right, ExecutionState state)
{
object b = TokenParser.VerifyUnderlyingType(right.Evaluate(state, token));
object a = TokenParser.VerifyUnderlyingType(left.Evaluate(state, token));
decimal x, y;
if (a is decimal)
x = (decimal)a;
else
{
TypeConverter tc = TypeDescriptor.GetConverter(a);
if (!tc.CanConvertTo(typeof(decimal)))
ThrowException(a);
x = (decimal)tc.ConvertTo(a, typeof(decimal));
}
if (b is decimal)
y = (decimal)b;
else
{
TypeConverter tc = TypeDescriptor.GetConverter(b);
if (!tc.CanConvertTo(typeof(decimal)))
ThrowException(b);
y = (decimal)tc.ConvertTo(b, typeof(decimal));
}
if (y == 0)
throw new InstructionExecutionException("I can't divide the first number by the second because the second is zero. i.e. Noone can divide by zero. Not even me.", token);
return x / y;
}
示例15: AsVector4
public static Vector4? AsVector4(Object state, IExpression expression, Vector4? failover)
{
if (expression == null || expression.IsValid == false) return failover;
Number[] result = expression.Evaluate(state);
if (result.Length > 0 && result[0].NumberType != NumberType.None)
{
if (result.Length > 1 && result[1].NumberType != NumberType.None)
{
if (result.Length > 2 && result[2].NumberType != NumberType.None)
{
if (result.Length > 3 && result[3].NumberType != NumberType.None)
{
return new Vector4(result[0].FloatValue, result[1].FloatValue, result[2].FloatValue, result[3].FloatValue);
}
else
{
return new Vector4(result[0].FloatValue, result[1].FloatValue, result[2].FloatValue, 0);
}
}
else
{
return new Vector4(result[0].FloatValue, result[1].FloatValue, 0, 0);
}
}
else
{
return new Vector4(result[0].FloatValue, 0, 0, 0);
}
}
return failover;
}