本文整理汇总了C#中IInternalContextAdapter.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IInternalContextAdapter.Get方法的具体用法?C# IInternalContextAdapter.Get怎么用?C# IInternalContextAdapter.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInternalContextAdapter
的用法示例。
在下文中一共展示了IInternalContextAdapter.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getObject
/// <summary> returns the value of the reference. Generally, this is only
/// called for dynamic proxies, as the static ones should have
/// been stored in the VMContext's localContext store
/// *
/// </summary>
/// <param name="context">Context to use for getting current value
/// </param>
/// <returns>Object value
/// *
///
/// </returns>
public Object getObject(IInternalContextAdapter context)
{
try
{
/*
* we need to output based on our type
*/
Object retObject = null;
if (type == ParserTreeConstants.REFERENCE)
{
/*
* two cases : scalar reference ($foo) or multi-level ($foo.bar....)
*/
if (numTreeChildren == 0)
{
/*
* if I am a single-level reference, can I not get get it out of my context?
*/
retObject = context.Get(singleLevelRef);
}
else
{
/*
* I need to let the AST produce it for me.
*/
retObject = nodeTree.Execute(null, context);
}
}
else if (type == ParserTreeConstants.OBJECT_ARRAY)
{
retObject = nodeTree.Value(context);
}
else if (type == ParserTreeConstants.INTEGER_RANGE)
{
retObject = nodeTree.Value(context);
}
else if (type == ParserTreeConstants.TRUE)
{
retObject = staticObject;
}
else if (type == ParserTreeConstants.FALSE)
{
retObject = staticObject;
}
else if (type == ParserTreeConstants.STRING_LITERAL)
{
retObject = nodeTree.Value(context);
}
else if (type == ParserTreeConstants.NUMBER_LITERAL)
{
retObject = staticObject;
}
else if (type == ParserTreeConstants.TEXT)
{
/*
* this really shouldn't happen. text is just a throwaway arg for #foreach()
*/
try
{
StringWriter writer = new StringWriter();
nodeTree.Render(context, writer);
retObject = writer;
}
catch(Exception e)
{
runtimeServices.Error(string.Format("VMProxyArg.getObject() : error rendering reference : {0}", e));
}
}
else if (type == GENERALSTATIC)
{
retObject = staticObject;
}
else
{
runtimeServices.Error(
string.Format("Unsupported VM arg type : VM arg = {0} type = {1}( VMProxyArg.getObject() )", callerReference, type));
}
return retObject;
}
catch(MethodInvocationException mie)
{
//.........这里部分代码省略.........
示例2: Render
/// <summary>
/// renders the #foreach() block
/// </summary>
public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
{
// do our introspection to see what our collection is
IEnumerator enumerator = GetIterator(context, node);
INode bodyNode = node.GetChild(3);
INode[][] sections = PrepareSections(bodyNode);
bool isFancyLoop = (sections != null);
if (enumerator == null && !isFancyLoop)
{
return true;
}
int counter = counterInitialValue;
// save the element key if there is one,
// and the loop counter
Object o = context.Get(elementKey);
Object ctr = context.Get(counterName);
if (enumerator != null && enumerator.MoveNext())
{
do
{
object current = enumerator.Current;
context.Put(counterName, counter);
//context.Put(hasNextName, enumerator.MoveNext() ? Boolean.TrueString : Boolean.FalseString);
context.Put(elementKey, current);
try
{
if (isFancyLoop)
{
if (counter == counterInitialValue)
{
ProcessSection(ForeachSectionEnum.BeforeAll, sections, context, writer);
}
else
{
ProcessSection(ForeachSectionEnum.Between, sections, context, writer);
}
ProcessSection(ForeachSectionEnum.Before, sections, context, writer);
// since 1st item is zero we invert odd/even
if ((counter - counterInitialValue) % 2 == 0)
{
ProcessSection(ForeachSectionEnum.Odd, sections, context, writer);
}
else
{
ProcessSection(ForeachSectionEnum.Even, sections, context, writer);
}
ProcessSection(ForeachSectionEnum.Each, sections, context, writer);
ProcessSection(ForeachSectionEnum.After, sections, context, writer);
}
else
{
bodyNode.Render(context, writer);
}
}
catch (BreakException)
{
break;
}
counter++;
} while (enumerator.MoveNext());
}
if (isFancyLoop)
{
if (counter > counterInitialValue)
{
ProcessSection(ForeachSectionEnum.AfterAll, sections, context, writer);
}
else
{
ProcessSection(ForeachSectionEnum.NoData, sections, context, writer);
}
}
// restores the loop counter (if we were nested)
// if we have one, else just removes
if (ctr == null)
{
context.Remove(counterName);
}
else
{
context.Put(counterName, ctr);
}
// restores element key if exists
//.........这里部分代码省略.........