当前位置: 首页>>代码示例>>C#>>正文


C# ScriptObject.SetValue方法代码示例

本文整理汇总了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);
        }
开发者ID:lunet-io,项目名称:scriban,代码行数:8,代码来源:MathFunctions.cs

示例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;
        }
开发者ID:lunet-io,项目名称:scriban,代码行数:13,代码来源:ScriptObjectInitializerExpression.cs

示例3: Register

 public static void Register(ScriptObject builtins)
 {
     if (builtins == null) throw new ArgumentNullException(nameof(builtins));
     builtins.SetValue("date", ScriptObject.From(typeof(ScriptDate)), true);
 }
开发者ID:lunet-io,项目名称:scriban,代码行数:5,代码来源:ScriptDate.cs

示例4: Register

 public static void Register(ScriptObject builtins)
 {
     if (builtins == null) throw new ArgumentNullException(nameof(builtins));
     builtins.SetValue("include", new IncludeFunction(), true);
 }
开发者ID:lunet-io,项目名称:scriban,代码行数:5,代码来源:IncludeFunction.cs

示例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);
        }
开发者ID:lunet-io,项目名称:scriban,代码行数:11,代码来源:StringFunctions.cs

示例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);
        }
开发者ID:lunet-io,项目名称:scriban,代码行数:31,代码来源:TestParser.cs

示例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);
        }
开发者ID:lunet-io,项目名称:scriban,代码行数:9,代码来源:ArrayFunctions.cs


注:本文中的ScriptObject.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。