本文整理汇总了C#中EvaluationContext.SwitchThisContext方法的典型用法代码示例。如果您正苦于以下问题:C# EvaluationContext.SwitchThisContext方法的具体用法?C# EvaluationContext.SwitchThisContext怎么用?C# EvaluationContext.SwitchThisContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EvaluationContext
的用法示例。
在下文中一共展示了EvaluationContext.SwitchThisContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
/// <summary>
/// Returns the last context item that matches selection expression.
/// </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)
{
IList list = context as IList;
if (list == null)
{
throw new ArgumentException(
"Selection can only be used on an instance of the type that implements IList.");
}
using (evalContext.SwitchThisContext())
{
BaseNode expression = (BaseNode) this.getFirstChild();
for (int i = list.Count - 1; i >= 0; i--)
{
object listItem = list[i];
evalContext.ThisContext = listItem;
bool isMatch = (bool)GetValue(expression, listItem, evalContext );
if (isMatch)
{
return listItem;
}
}
}
return null;
}
示例2: Get
/// <summary>
/// Returns a <see cref="IList" /> containing results of evaluation
/// of selection expression against each node in the context.
/// </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 enumerable = context as IEnumerable;
if (enumerable == null)
{
throw new ArgumentException(
"Selection can only be used on an instance of the type that implements IEnumerable.");
}
var expression = (BaseNode) getFirstChild();
var minIndexExpression = (BaseNode) expression.getNextSibling();
var maxIndexExpression = (minIndexExpression == null) ? null : (BaseNode) minIndexExpression.getNextSibling();
var minIndex = (int) ((minIndexExpression == null)
? int.MinValue
: GetValue(minIndexExpression, context, evalContext));
var maxIndex = (int) ((maxIndexExpression == null)
? int.MaxValue
: GetValue(maxIndexExpression, context, evalContext));
IList selectionList = new ArrayList();
using (evalContext.SwitchThisContext())
{
var found = 0;
foreach (var item in enumerable)
{
evalContext.ThisContext = item;
var isMatch = (bool) GetValue(expression, item, evalContext);
if (isMatch)
{
if (minIndex <= found && found <= maxIndex)
{
selectionList.Add(item);
}
found++;
if (found > maxIndex)
{
break; // don't look any further
}
}
}
}
return selectionList;
}
示例3: Get
/// <summary>
/// Returns a <see cref="IList"/> containing results of evaluation
/// of projection expression against each node in the context.
/// </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)
{
IEnumerable enumerable = context as IEnumerable;
if(enumerable == null)
{
throw new ArgumentException(
"Projection can only be used on an instance of the type that implements IEnumerable.");
}
BaseNode expression = (BaseNode) this.getFirstChild();
IList projectedList = new ArrayList();
using (evalContext.SwitchThisContext())
{
foreach(object o in enumerable)
{
evalContext.ThisContext = o;
projectedList.Add(GetValue(expression, o, evalContext));
}
}
return projectedList;
}
示例4: Get
/// <summary>
/// Returns the first context item that matches selection expression.
/// </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)
{
IEnumerable enumerable = context as IEnumerable;
if (enumerable == null)
{
throw new ArgumentException(
"Selection can only be used on an instance of the type that implements IEnumerable.");
}
BaseNode expression = (BaseNode) this.getFirstChild();
using (evalContext.SwitchThisContext())
{
foreach (object o in enumerable)
{
evalContext.ThisContext = o;
bool isMatch = (bool)GetValue(expression, o, evalContext);
if (isMatch)
{
return o;
}
}
}
return null;
}