本文整理汇总了C#中TemplateContext.ExitFunction方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateContext.ExitFunction方法的具体用法?C# TemplateContext.ExitFunction怎么用?C# TemplateContext.ExitFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TemplateContext
的用法示例。
在下文中一共展示了TemplateContext.ExitFunction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Call
public static object Call(TemplateContext context, ScriptNode callerContext, object functionObject, List<ScriptExpression> arguments = null)
{
if (callerContext == null) throw new ArgumentNullException(nameof(callerContext));
if (functionObject == null)
{
throw new ScriptRuntimeException(callerContext.Span, $"The target function [{callerContext}] is null");
}
var function = functionObject as ScriptFunction;
var externFunction = functionObject as IScriptCustomFunction;
if (function == null && externFunction == null)
{
throw new ScriptRuntimeException(callerContext.Span, $"Invalid object function [{functionObject?.GetType()}]");
}
ScriptBlockStatement blockDelegate = null;
if (context.BlockDelegates.Count > 0)
{
blockDelegate = context.BlockDelegates.Pop();
}
var argumentValues = new ScriptArray();
if (arguments != null)
{
foreach (var argument in arguments)
{
var value = context.Evaluate(argument);
// Handle parameters expansion for a function call when the operator ^ is used
var unaryExpression = argument as ScriptUnaryExpression;
if (unaryExpression != null && unaryExpression.ExpandParameters(value, argumentValues))
{
continue;
}
argumentValues.Add(value);
}
}
// Handle pipe arguments here
if (context.PipeArguments.Count > 0)
{
var additionalArgument = context.PipeArguments.Pop();
var value = context.Evaluate(additionalArgument);
// Handle parameters expansion for a function call when the operator ~ is used
var unaryExpression = additionalArgument as ScriptUnaryExpression;
if (unaryExpression == null || !unaryExpression.ExpandParameters(value, argumentValues))
{
argumentValues.Add(value);
}
}
object result = null;
context.EnterFunction(callerContext);
try
{
if (externFunction != null)
{
result = externFunction.Evaluate(context, callerContext, argumentValues, blockDelegate);
}
else
{
context.SetValue(ScriptVariable.Arguments, argumentValues, true);
// Set the block delegate
if (blockDelegate != null)
{
context.SetValue(ScriptVariable.BlockDelegate, blockDelegate, true);
}
result = context.Evaluate(function.Body);
}
}
finally
{
context.ExitFunction();
}
// Restore the flow state to none
context.FlowState = ScriptFlowState.None;
return result;
}