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


C# Engine.GetValue方法代码示例

本文整理汇总了C#中Engine.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.GetValue方法的具体用法?C# Engine.GetValue怎么用?C# Engine.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Engine的用法示例。


在下文中一共展示了Engine.GetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var engine = new Engine(cfg => cfg.AllowClr())
                .SetValue("print", new Action<object>(Console.WriteLine))
            ;

            var filename = args.Length > 0 ? args[0] : "";
            if (!String.IsNullOrEmpty(filename))
            {
                if (!File.Exists(filename))
                {
                    Console.WriteLine("Could not find file: {0}", filename);
                }

                var script = File.ReadAllText(filename);
                var result = engine.GetValue(engine.Execute(script).GetCompletionValue());
                return;
            }

            Assembly assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
            string version = fvi.FileVersion;

            Console.WriteLine("Welcome to Jint ({0})", version);
            Console.WriteLine("Type 'exit' to leave, 'print()' to write on the console.");
            Console.WriteLine();

            var defaultColor = Console.ForegroundColor;
            while (true)
            {
                Console.ForegroundColor = defaultColor;
                Console.Write("jint> ");
                var input = Console.ReadLine();
                if (input == "exit")
                {
                    return;
                }

                try
                {
                    var result = engine.GetValue(engine.Execute(input).GetCompletionValue());
                    if (result.Type != Types.None && result.Type != Types.Null && result.Type != Types.Undefined)
                    {
                        var str = TypeConverter.ToString(engine.Json.Stringify(engine.Json, Arguments.From(result, Undefined.Instance, "  ")));
                        Console.WriteLine("=> {0}", str);
                    }
                }
                catch (JavaScriptException je)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(je.ToString());
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(e.Message);
                }
                
            }
        }
开发者ID:BusinessActs,项目名称:jint,代码行数:60,代码来源:Program.cs

示例2: CanSetCustomConverters

        public void CanSetCustomConverters()
        {

            var engine1 = new Engine();
            engine1.SetValue("p", new { Test = true });
            engine1.Execute("var result = p.Test;");
            Assert.True((bool)engine1.GetValue("result").ToObject());

            var engine2 = new Engine(o => o.AddObjectConverter(new NegateBoolConverter()));
            engine2.SetValue("p", new { Test = true });
            engine2.Execute("var result = p.Test;");
            Assert.False((bool)engine2.GetValue("result").ToObject());

        }
开发者ID:Willy-Kimura,项目名称:jint,代码行数:14,代码来源:InteropTests.cs

示例3: CanConvertEnumsToString

 public void CanConvertEnumsToString()
 {
     var engine1 = new Engine(o => o.AddObjectConverter(new EnumsToStringConverter()))
         .SetValue("assert", new Action<bool>(Assert.True));
     engine1.SetValue("p", new { Comparison = StringComparison.CurrentCulture });
     engine1.Execute("assert(p.Comparison === 'CurrentCulture');");
     engine1.Execute("var result = p.Comparison;");
     Assert.Equal("CurrentCulture", (string)engine1.GetValue("result").ToObject());
 }
开发者ID:sebastienros,项目名称:jint,代码行数:9,代码来源:InteropTests.cs


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