本文整理汇总了C#中EvaluationContext类的典型用法代码示例。如果您正苦于以下问题:C# EvaluationContext类的具体用法?C# EvaluationContext怎么用?C# EvaluationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EvaluationContext类属于命名空间,在下文中一共展示了EvaluationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
/// <summary>
/// Method called by the EvaluationEngine to evaluate the function.
/// </summary>
/// <param name="context">The evaluation context instance.</param>
/// <param name="args">The IFuctionParameters that will be used as arguments to the function.</param>
/// <returns></returns>
public override EvaluationValue Evaluate(EvaluationContext context, params IFunctionParameter[] args)
{
if (context == null) throw new ArgumentNullException("context");
if (args == null) throw new ArgumentNullException("args");
int argCount = GetIntegerArgument(args, 0);
if (args.Length - 1 < argCount)
{
return EvaluationValue.Indeterminate;
}
else if (argCount == 0)
{
return EvaluationValue.True;
}
else
{
int count = 0;
for (int i = 1; i < args.Length; i++)
{
if (GetBooleanArgument(args, i))
{
count++;
}
if (count == argCount)
{
return EvaluationValue.True;
}
}
return EvaluationValue.False;
}
}
示例2: Evaluate
public override sealed double Evaluate(Tree<SyntaxToken> tree, EvaluationContext context)
{
var leaf = tree.Leafs[0];
double value = leaf.Value.Evaluate(leaf, context);
return Evaluate(value);
}
示例3: Get
/// <summary>
/// Returns a value for the logical inequality operator node.
/// </summary>
/// <param name="context">Context to evaluate expressions against.</param>
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
object leftVal = GetLeftValue( context, evalContext );
object rightVal = GetRightValue( context, evalContext );
if (leftVal == null)
{
return (rightVal != null);
}
else if (rightVal == null)
{
return true;
}
else if (leftVal.GetType() == rightVal.GetType())
{
if (leftVal is Array)
{
return !ArrayUtils.AreEqual(leftVal as Array, rightVal as Array);
}
else
{
return !leftVal.Equals(rightVal);
}
}
else
{
return CompareUtils.Compare(leftVal, rightVal) != 0;
}
}
示例4: Get
/// <summary>
/// Evaluates function represented by this node.
/// </summary>
/// <param name="context">Context to evaluate expressions against.</param>
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Result of the function evaluation.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
var name = getText();
var argValues = ResolveArguments(evalContext);
var function = evalContext.Variables[name];
// delegate?
var callback = function as Delegate;
if (callback != null)
{
return InvokeDelegate(callback, argValues);
}
// lambda?
var lambda = function as LambdaExpressionNode;
if (lambda != null)
{
try
{
return GetValueWithArguments(lambda, context, evalContext, argValues);
}
catch (ArgumentMismatchException ame)
{
throw new InvalidOperationException( "Failed executing function " + name + ": " + ame.Message );
}
}
if (function == null)
{
throw new InvalidOperationException("Function '" + name + "' is not defined.");
}
throw new InvalidOperationException("Function '" + name + "' is defined but of unknown type.");
}
示例5: Get
/// <summary>
/// Creates new instance of the type defined by this node.
/// </summary>
/// <param name="context">Context to evaluate expressions against.</param>
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
object[] argValues = ResolveArguments(evalContext);
IDictionary namedArgValues = ResolveNamedArguments(evalContext);
if (constructor == null)
{
lock(this)
{
if (constructor == null)
{
constructor = InitializeNode(argValues, namedArgValues);
}
}
}
object[] paramValues = (isParamArray ? ReflectionUtils.PackageParamArray(argValues, argumentCount, paramArrayType) : argValues);
object instance = constructor.Invoke(paramValues);
if (namedArgValues != null)
{
SetNamedArguments(instance, namedArgValues);
}
return instance;
}
示例6: Evaluate
protected override object Evaluate(object context, EvaluationContext evalContext)
{
if (_value == null)
{
lock (this)
{
if (_value == null)
{
string n = this.getText();
char lastChar = n.ToLower()[n.Length - 1];
if (Char.IsDigit(lastChar))
{
_value = Double.Parse(n, NumberFormatInfo.InvariantInfo);
}
else
{
n = n.Substring(0, n.Length - 1);
if (lastChar == 'm')
{
_value = Decimal.Parse(n, NumberFormatInfo.InvariantInfo);
}
else if (lastChar == 'f')
{
_value = Single.Parse(n, NumberFormatInfo.InvariantInfo);
}
else
{
_value = Double.Parse(n, NumberFormatInfo.InvariantInfo);
}
}
}
}
}
return _value;
}
示例7: Get
/// <summary>
/// Returns a value for the logical equality operator node.
/// </summary>
/// <param name="context">Context to evaluate expressions against.</param>
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
var lhs = GetLeftValue(context, evalContext);
var rhs = GetRightValue(context, evalContext);
if (lhs == null)
{
return (rhs == null);
}
if (rhs == null)
{
return false;
}
if (lhs.GetType() == rhs.GetType())
{
if (lhs is Array)
{
return ArrayUtils.AreEqual(lhs as Array, rhs as Array);
}
return lhs.Equals(rhs);
}
if (lhs.GetType().IsEnum && rhs is string)
{
return lhs.Equals(Enum.Parse(lhs.GetType(), (string)rhs));
}
if (rhs.GetType().IsEnum && lhs is string)
{
return rhs.Equals(Enum.Parse(rhs.GetType(), (string)lhs));
}
return CompareUtils.Compare(lhs, rhs) == 0;
}
示例8: Evaluate
/// <summary>
/// Evaluates the function.
/// </summary>
/// <param name="context">The evaluation context instance.</param>
/// <param name="args">The function arguments.</param>
/// <returns>The result value of the function evaluation.</returns>
public override EvaluationValue Evaluate(EvaluationContext context, params IFunctionParameter[] args)
{
if (context == null) throw new ArgumentNullException("context");
if (args == null) throw new ArgumentNullException("args");
var retBag = new BagValue(DataType);
IFunction functionDup = DataType.IsInFunction;
foreach (object par1 in args[0].Elements)
{
EvaluationValue retVal = functionDup.Evaluate(context, new EvaluationValue(par1, args[0].GetType(context)), retBag);
if (!retVal.BoolValue)
{
retBag.Add(new EvaluationValue(par1, args[0].GetType(context)));
}
}
foreach (object par2 in args[1].Elements)
{
EvaluationValue retVal = functionDup.Evaluate(context, new EvaluationValue(par2, args[1].GetType(context)), retBag);
if (!retVal.BoolValue)
{
retBag.Add(new EvaluationValue(par2, args[1].GetType(context)));
}
}
return new EvaluationValue(retBag, DataType);
}
示例9: Get
/// <summary>
/// Returns a value for the logical AND operator node.
/// </summary>
/// <param name="context">Context to evaluate expressions against.</param>
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
object l = GetLeftValue(context, evalContext);
if (NumberUtils.IsInteger(l))
{
object r = GetRightValue(context, evalContext);
if (NumberUtils.IsInteger(r))
{
return NumberUtils.BitwiseAnd(l, r);
}
}
else if (l is Enum)
{
object r = GetRightValue(context, evalContext);
if (l.GetType() == r.GetType())
{
Type enumType = l.GetType();
Type integralType = Enum.GetUnderlyingType(enumType);
l = Convert.ChangeType(l, integralType);
r = Convert.ChangeType(r, integralType);
object result = NumberUtils.BitwiseAnd(l, r);
return Enum.ToObject(enumType, result);
}
}
return Convert.ToBoolean(l) &&
Convert.ToBoolean(GetRightValue(context, evalContext));
}
示例10: Get
/// <summary>
/// Returns a value for the logical AND operator node.
/// </summary>
/// <param name="context">Context to evaluate expressions against.</param>
/// <param name="evalContext">Current expression evaluation context.</param>
/// <returns>Node's value.</returns>
protected override object Get(object context, EvaluationContext evalContext)
{
var lhs = GetLeftValue(context, evalContext);
if (NumberUtils.IsInteger(lhs))
{
var rhs = GetRightValue(context, evalContext);
if (NumberUtils.IsInteger(rhs))
{
return NumberUtils.BitwiseAnd(lhs, rhs);
}
}
else if (lhs is Enum)
{
var rhs = GetRightValue(context, evalContext);
if (lhs.GetType() == rhs.GetType())
{
var enumType = lhs.GetType();
var integralType = Enum.GetUnderlyingType(enumType);
lhs = Convert.ChangeType(lhs, integralType);
rhs = Convert.ChangeType(rhs, integralType);
var result = NumberUtils.BitwiseAnd(lhs, rhs);
return Enum.ToObject(enumType, result);
}
}
return Convert.ToBoolean(lhs) &&
Convert.ToBoolean(GetRightValue(context, evalContext));
}
示例11: Eval
public override object Eval(EvaluationContext.Context evaluationContext)
{
string baseCurrencyCode = _baseCurrencyCode.Eval(evaluationContext) as string;
string variableCurrencyCode = _variableCurrencyCode.Eval(evaluationContext) as string;
return evaluationContext.CurrencyDataSource.GetCurrencyPairData(baseCurrencyCode, variableCurrencyCode).ExchangeRates;
}
示例12: Evaluate
protected override object Evaluate(object context, EvaluationContext evalContext)
{
string text = Left.EvaluateInternal( context, evalContext ) as string;
string pattern = Right.EvaluateInternal( context, evalContext ) as string;
return StrLike(text, pattern);
}
示例13: Evaluate
/// <summary>
/// Evaluates the function.
/// </summary>
/// <param name="context">The evaluation context instance.</param>
/// <param name="args">The function arguments.</param>
/// <returns>The result value of the function evaluation.</returns>
public override EvaluationValue Evaluate(EvaluationContext context, params IFunctionParameter[] args)
{
if (context == null) throw new ArgumentNullException("context");
if (args == null) throw new ArgumentNullException("args");
IFunction function = DataType.EqualFunction;
foreach (object par1 in args[0].Elements)
{
bool hasFound = false;
foreach (object par2 in args[1].Elements)
{
EvaluationValue retVal = function.Evaluate(context, new EvaluationValue(par1, args[0].GetType(context)), new EvaluationValue(par2, args[1].GetType(context)));
if (retVal.BoolValue)
{
hasFound = true;
break;
}
}
if (!hasFound)
{
return EvaluationValue.False;
}
}
return EvaluationValue.True;
}
示例14: Eval
public override object Eval(EvaluationContext.Context evaluationContext)
{
int numberOfDays = (int)_length.LengthExpr.Eval(evaluationContext);
if (_length.PeriodicType == PeriodicType.Month)
{
numberOfDays *= 30;
}
DateTime requestDate = (DateTime) _requestDate.Eval(evaluationContext);
if (TimeDataSetAccessor is ExchangeRateAccessor)
{
FXStrategy.DataAccess.TimeSeriesCollection<FXStrategy.DataAccess.ExchangeRateBid> timeSeries
= (FXStrategy.DataAccess.TimeSeriesCollection<FXStrategy.DataAccess.ExchangeRateBid>)
_timeDataSetAccessor.Eval(evaluationContext);
return timeSeries.MovingAvg(requestDate, numberOfDays);
}
else if (TimeDataSetAccessor is InterestRateAccessor)
{
FXStrategy.DataAccess.TimeSeriesCollection<FXStrategy.DataAccess.InterestRate> timeSeries
= (FXStrategy.DataAccess.TimeSeriesCollection<FXStrategy.DataAccess.InterestRate>)
_timeDataSetAccessor.Eval(evaluationContext);
return timeSeries.MovingAvg(requestDate, numberOfDays);
}
else
throw new Exception("Unhandled TimeDataSetAccessor: " + TimeDataSetAccessor.GetType().Name);
}
示例15: Evaluate
protected override object Evaluate(object context, EvaluationContext evalContext)
{
object n = Operand.EvaluateInternal( context, evalContext );
if (!NumberUtils.IsNumber(n))
throw new ArgumentException("Specified operand is not a number. Only numbers support unary minus operator.");
return NumberUtils.Negate(n);
}