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


C# Irony.PushScope方法代码示例

本文整理汇总了C#中Irony.PushScope方法的典型用法代码示例。如果您正苦于以下问题:C# Irony.PushScope方法的具体用法?C# Irony.PushScope怎么用?C# Irony.PushScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Irony的用法示例。


在下文中一共展示了Irony.PushScope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoEvaluate

        protected override object DoEvaluate(Irony.Interpreter.ScriptThread thread)
        {
            object retval = null;
            thread.CurrentNode = this;  //standard prolog
            IEnumerable<object> o = null;

            string functionName = function.ChildNodes[0].FindTokenAndGetText();
            switch (functionName.ToLowerInvariant())
            {
                case "count":
                    o = Left as IEnumerable<object>;
                    if (o != null)
                        retval = o.Count();
                    else
                        retval = -1;
                    break;
                case "range":
                    o = Left as IEnumerable<object>;
                    if (o != null)
                    {
                        // by default return the first
                        int iFrom = GetIndex(thread, Arguments[0], o, 0);
                        int iTo = GetIndex(thread, Arguments[1], o, iFrom);

                        if (iFrom < 0)
                            iFrom = 0;
                        if (iTo >= o.Count())
                            iTo = o.Count();

                        List<object> tretval = new List<object>();
                        for (int i = iFrom; i <= iTo; i++)
                        {
                            tretval.Add(o.ElementAt(i));
                        }
                        retval = tretval;
                    }
                    else
                        retval = null;
                    break;
                case "where":

                    o = Left as IEnumerable<object>;
                    if (o != null)
                    {

                        List<object> tretvalWhere = new List<object>();
                        foreach (var item in o)
                        {
                            // todo: bonghi: needs to check the context is set here.
                            var scpInfo = new ScopeInfo(this, false);
                            object[] oIfc = new object[] { item };
                            thread.PushScope(scpInfo, oIfc);

                            try
                            {
                                object oCondition = Arguments[0].Evaluate(thread);
                                if ((bool)oCondition)
                                {
                                    tretvalWhere.Add(item);
                                }
                            }
                            catch (Exception)
                            {
                                // if problems just ignore so that statements that don't compute (say for missing properties) are still ok.
                            }
                            thread.PopScope();
                        }

                        retval = tretvalWhere;
                    }
                    else
                        retval = null;
                    break;
                default:
                    throw new Exception("Not implemented: " + functionName);
            }

            thread.CurrentNode = Parent; //standard epilog
            return retval;
        }
开发者ID:bnaand,项目名称:xBim-Toolkit,代码行数:80,代码来源:SelectFunctionNode.cs


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