本文整理汇总了C#中IEnvironment.CreateFunction方法的典型用法代码示例。如果您正苦于以下问题:C# IEnvironment.CreateFunction方法的具体用法?C# IEnvironment.CreateFunction怎么用?C# IEnvironment.CreateFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnvironment
的用法示例。
在下文中一共展示了IEnvironment.CreateFunction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
public IJsValue Evaluate(IEnvironment environment)
{
var f = environment.CreateFunction(
Name,
Arguments.Select(a => a.ReferenceCast<IAstWithName>().Name).ToList(),
Statements);
if (!string.IsNullOrEmpty(Name))
{
environment.CreateReference(Name,f);
}
return f;
}
示例2: Construct
public override IObject Construct(IEnvironment environment, IArgs args)
{
string formalParametersString, functionBody;
if (args.IsEmpty)
{
formalParametersString = "";
functionBody = "";
}
else if (args.Count == 1)
{
formalParametersString = "";
functionBody = args[0].ConvertToString().BaseValue;
}
else
{
var sb = new StringBuilder();
var limit = args.Count - 1;
for (int i = 0; i < limit; i++)
{
if (sb.Length > 0)
{
sb.Append(",");
}
sb.Append(args[i].ConvertToString().BaseValue);
}
formalParametersString = sb.ToString();
functionBody = args[limit].ConvertToString().BaseValue;
}
var compiler = new CompilerService(environment);
var executableCode = compiler.CompileFunctionCode(functionBody, environment.Context.Strict);
var formalParameters = compiler.CompileFormalParameterList(formalParametersString);
var func = environment.CreateFunction(executableCode, formalParameters, environment.GlobalEnvironment);
return func;
}