<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ClearScript.NET 腳本工具

          聯(lián)合創(chuàng)作 · 2023-09-28 14:06

          ClearScript 可以幫助開發(fā)者添加腳本到 .NET 應(yīng)用,當前支持 JavaScript (V8 和 JScript) 和 VBScript。

          示例

          using System;
          using Microsoft.ClearScript;
          using Microsoft.ClearScript.V8;
          // create a script engine
          using (var engine = new V8ScriptEngine())
          {
              // expose a host type
              engine.AddHostType("Console", typeof(Console));
              engine.Execute("Console.WriteLine('{0} is an interesting number.', Math.PI)");
              // expose a host object
              engine.AddHostObject("random", new Random());
              engine.Execute("Console.WriteLine(random.NextDouble())");
              // expose entire assemblies
              engine.AddHostObject("lib", new HostTypeCollection("mscorlib", "System.Core"));
              engine.Execute("Console.WriteLine(lib.System.DateTime.Now)");
              // create a host object from script
              engine.Execute(@"
                  birthday = new lib.System.DateTime(2007, 5, 22);
                  Console.WriteLine(birthday.ToLongDateString());
              ");
              // use a generic class from script
              engine.Execute(@"
                  Dictionary = lib.System.Collections.Generic.Dictionary;
                  dict = new Dictionary(lib.System.String, lib.System.Int32);
                  dict.Add('foo', 123);
              ");
              // call a host method with an output parameter
              engine.AddHostObject("host", new HostFunctions());
              engine.Execute(@"
                  intVar = host.newVar(lib.System.Int32);
                  found = dict.TryGetValue('foo', intVar.out);
                  Console.WriteLine('{0} {1}', found, intVar);
              ");
              // create and populate a host array
              engine.Execute(@"
                  numbers = host.newArr(lib.System.Int32, 20);
                  for (var i = 0; i < numbers.Length; i++) { numbers[i] = i; }
                  Console.WriteLine(lib.System.String.Join(', ', numbers));
              ");
              // create a script delegate
              engine.Execute(@"
                  Filter = lib.System.Func(lib.System.Int32, lib.System.Boolean);
                  oddFilter = new Filter(function(value) {
                      return (value & 1) ? true : false;
                  });
              ");
              // use LINQ from script
              engine.Execute(@"
                  oddNumbers = numbers.Where(oddFilter);
                  Console.WriteLine(lib.System.String.Join(', ', oddNumbers));
              ");
              // use a dynamic host object
              engine.Execute(@"
                  expando = new lib.System.Dynamic.ExpandoObject();
                  expando.foo = 123;
                  expando.bar = 'qux';
                  delete expando.foo;
              ");
              // call a script function
              engine.Execute("function print(x) { Console.WriteLine(x); }");
              engine.Script.print(DateTime.Now.DayOfWeek);
              // examine a script object
              engine.Execute("person = { name: 'Fred', age: 5 }");
              Console.WriteLine(engine.Script.person.name);
          }


          瀏覽 21
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美激情性爱网站 | 日韩一区二区免费视频 | 欧美口爆| 91精品国产91久久久久 | 2018天天日天天操 |