本文整理汇总了C#中ScriptObject.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptObject.SetValue方法的具体用法?C# ScriptObject.SetValue怎么用?C# ScriptObject.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptObject
的用法示例。
在下文中一共展示了ScriptObject.SetValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public static void Register(ScriptObject builtins)
{
if (builtins == null) throw new ArgumentNullException(nameof(builtins));
var mathObject = ScriptObject.From(typeof(MathFunctions));
mathObject.SetValue("round", new DelegateCustomFunction(Round), true);
builtins.SetValue("math", mathObject, true);
}
示例2: Evaluate
public override void Evaluate(TemplateContext context)
{
var scriptObject = new ScriptObject();
foreach (var member in Members)
{
var variable = member.Key as ScriptVariable;
var literal = member.Key as ScriptLiteral;
var name = variable?.Name ?? literal?.Value?.ToString();
scriptObject.SetValue(name, context.Evaluate(member.Value), false);
}
context.Result = scriptObject;
}
示例3: Register
public static void Register(ScriptObject builtins)
{
if (builtins == null) throw new ArgumentNullException(nameof(builtins));
builtins.SetValue("date", ScriptObject.From(typeof(ScriptDate)), true);
}
示例4: Register
public static void Register(ScriptObject builtins)
{
if (builtins == null) throw new ArgumentNullException(nameof(builtins));
builtins.SetValue("include", new IncludeFunction(), true);
}
示例5: Register
public static void Register(ScriptObject builtins)
{
if (builtins == null) throw new ArgumentNullException(nameof(builtins));
var stringObject = ScriptObject.From(typeof(StringFunctions));
// We need to handle "slice"/"truncate" differently as we have an optional parameters
stringObject.SetValue("slice", new DelegateCustomFunction(Slice), true);
builtins.SetValue("string", stringObject, true);
}
示例6: TestFunctionCallInExpression
public void TestFunctionCallInExpression()
{
var lexer = new Lexer(@"{{
with math
round pi
end
}}");
var parser = new Parser(lexer);
var scriptPage = parser.Run();
foreach (var message in parser.Messages)
{
Console.WriteLine(message);
}
Assert.False(parser.HasErrors);
Assert.NotNull(scriptPage);
var rootObject = new ScriptObject();
rootObject.SetValue("math", ScriptObject.From(typeof(MathObject)), true);
var context = new TemplateContext();
context.PushGlobal(rootObject);
scriptPage.Evaluate(context);
context.PopGlobal();
// Result
var result = context.Output.ToString();
Console.WriteLine(result);
}
示例7: Register
public static void Register(ScriptObject builtins)
{
if (builtins == null) throw new ArgumentNullException(nameof(builtins));
var arrayObject = ScriptObject.From(typeof (ArrayFunctions));
arrayObject.SetValue("sort", new DelegateCustomFunction(Sort), true);
arrayObject.SetValue("map", new DelegateCustomFunction(Map), true);
builtins.SetValue("array", arrayObject, true);
}