当前位置: 首页>>代码示例>>C#>>正文


C# EvaluationContext.SwitchThisContext方法代码示例

本文整理汇总了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;
        }
开发者ID:Binodesk,项目名称:spring-net,代码行数:32,代码来源:SelectionLastNode.cs

示例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;
        }
开发者ID:kog,项目名称:Solenoid-Expressions,代码行数:53,代码来源:SelectionNode.cs

示例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;
        }
开发者ID:Binodesk,项目名称:spring-net,代码行数:28,代码来源:ProjectionNode.cs

示例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;
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:30,代码来源:SelectionFirstNode.cs


注:本文中的EvaluationContext.SwitchThisContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。