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