本文整理汇总了C#中Environment.AssignLocal方法的典型用法代码示例。如果您正苦于以下问题:C# Environment.AssignLocal方法的具体用法?C# Environment.AssignLocal怎么用?C# Environment.AssignLocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Environment
的用法示例。
在下文中一共展示了Environment.AssignLocal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessArguments
public void ProcessArguments(object parameters, object[] arguments, Environment localEnvironment)
{
// TODO: Better checking for congruent arguments, better error handling
if (parameters == null)
return; // No parameters so nothing to do
if (parameters is Symbol)
{
localEnvironment.AssignLocal((Symbol)parameters, Runtime.FromArray(arguments, 0));
return;
}
int i = 0;
ISequence parameterSequence = Runtime.Seq(parameters);
while (parameterSequence != null)
{
object parameter = parameterSequence.First();
if (parameter is Symbol)
{
if (parameter == Symbol.FromName("&"))
{
// The next parameter is a rest parameter and receives all the
// remaining arguments
object rest = Runtime.FromArray(arguments, i);
localEnvironment.AssignLocal((Symbol)parameterSequence.Rest().First(), rest);
parameterSequence = null;
}
else
{
// It's a required parameter
localEnvironment.AssignLocal((Symbol)parameter, arguments[i]);
parameterSequence = parameterSequence.Rest();
i++;
}
}
else if (parameter is ISequence)
{
// It's an optional parameter
Symbol name = (Symbol)((ISequence)parameter).First();
object expr = ((ISequence)parameter).Rest().First();
if (i < arguments.Length)
{
// The optional argument is present
localEnvironment.AssignLocal(name, arguments[i]);
i++;
}
else
{
// The optional argument is missing
// TODO: Optional argument defaults really should have been compiled by now
object o = Compiler.Eval(expr, localEnvironment);
localEnvironment.AssignLocal(name, o);
}
parameterSequence = parameterSequence.Rest();
}
}
}