块作用域闭包问题

结果正确:1

容易引入JSB:1

 1 public class Program
2 {
3 static List<Action> createActions()
4 {
5 List<Action> arr = new List<Action>();
6 for (int i = 0; i < 10; i++)
7 {
8 {
9 int j = i;
10 arr.Add(() =>
11 {
12 Console.WriteLine(j.ToString());
13 });
14 }
15 }
16 return arr;
17 }
18 static void bbtest()
19 {
20 var arr = createActions();
21 for (int i = 0; i < arr.Count; i++)
22 {
23 arr[i]();
24 }
25 }
26 public static void Main()
27 {
28 bbtest();
29 //Console.WriteLine("Hello World!");
30 }
31 }
 1 /**
2 * @compiler Bridge.NET 15.3.0
3 */
4 Bridge.assembly("Demo", function ($asm, globals) {
5 "use strict";
6
7 Bridge.define("Demo.Program", {
8 statics: {
9 createActions: function () {
10 var arr = new (System.Collections.Generic.List$1(Function))();
11 for (var i = 0; i < 10; i = (i + 1) | 0) {
12 (function () {
13 {
14 var j = i;
15 arr.add(function () {
16 Bridge.Console.log(j.toString());
17 });
18 }
19 }).call(this);
20 }
21 return arr;
22 },
23 bbtest: function () {
24 var arr = Demo.Program.createActions();
25 for (var i = 0; i < arr.getCount(); i = (i + 1) | 0) {
26 arr.getItem(i)();
27 }
28 }
29 },
30 $main: function () {
31 Demo.Program.bbtest();
32 //Console.WriteLine("Hello World!");
33 }
34 });
35 });
 1 0
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9

ref/out

结果正确:1

容易引入JSB:1

 1 public class Program
2 {
3 class Apple
4 {
5 public int price;
6 }
7 static void testRef(ref int v)
8 {
9 v++;
10 }
11 static void testOut(out Apple a)
12 {
13 a = new Apple();
14 a.price = 44;
15 }
16 public static void Main()
17 {
18 int v = 5;
19 testRef(ref v);
20 Console.WriteLine(v);
21
22 Apple a = new Apple();
23 testOut(out a);
24 }
25 }
 1 /**
2 * @compiler Bridge.NET 15.3.0
3 */
4 Bridge.assembly("Demo", function ($asm, globals) {
5 "use strict";
6
7 Bridge.define("Demo.Program", {
8 statics: {
9 testRef: function (v) {
10 v.v = (v.v + 1) | 0;
11 },
12 testOut: function (a) {
13 a.v = new Demo.Program.Apple();
14 a.v.price = 44;
15 }
16 },
17 $main: function () {
18 var v = { v : 5 };
19 Demo.Program.testRef(v);
20 Bridge.Console.log(v.v);
21
22 var a = { v : new Demo.Program.Apple() };
23 Demo.Program.testOut(a);
24 }
25 });
26
27 Bridge.define("Demo.Program.Apple", {
28 price: 0
29 });
30 });
1 6

重载函数

结果正确:1

容易引入JSB:? 重载函数是以$1 $2结尾的。可以的,看下面第3个代码,对重载函数按一定规则进行排序。

 1 public class Program
2 {
3 static void hello(int v)
4 {
5 }
6 static void hello(string v)
7 {
8 }
9 static void hello(int a, int b)
10 {
11 }
12 public static void Main()
13 {
14 }
15 }
 1 /**
2 * @compiler Bridge.NET 15.3.0
3 */
4 Bridge.assembly("Demo", function ($asm, globals) {
5 "use strict";
6
7 Bridge.define("Demo.Program", {
8 statics: {
9 hello: function (v) {
10 },
11 hello$2: function (v) {
12 },
13 hello$1: function (a, b) {
14 }
15 },
16 $main: function () {
17 }
18 });
19 });
 1 string MethodToString(MethodInfo m)
2 {
3 StringBuilder sb = new StringBuilder();
4
5 sb.Append(m.ReturnType.ToString()).Append(" ");
6 sb.Append(m.Name).Append(" ");
7 sb.Append(m.GetGenericArguments().Length).Append(" ");
8
9 foreach (var p in m.GetParameters())
10 {
11 sb.Append(p.ParameterType.ToString()).Append(" ");
12 }
13 return sb.ToString();
14 }

结构体

结果正确:1

容易引入JSB:1

 1 public class Program
2 {
3 struct A
4 {
5 public int v;
6 }
7 static void Test(A a)
8 {
9 a.v = 4;
10 }
11 public static void Main()
12 {
13 A a = new A();
14 a.v = 5;
15 Test(a);
16 Console.WriteLine(a.v);
17 }
18 }
 1 /**
2 * @compiler Bridge.NET 15.3.0
3 */
4 Bridge.assembly("Demo", function ($asm, globals) {
5 "use strict";
6
7 Bridge.define("Demo.Program", {
8 statics: {
9 test: function (a) {
10 a.v = 4;
11 }
12 },
13 $main: function () {
14 var a = new Demo.Program.A();
15 a.v = 5;
16 Demo.Program.test(a.$clone());
17 Bridge.Console.log(a.v);
18 }
19 });
20
21 Bridge.define("Demo.Program.A", {
22 $kind: "struct",
23 statics: {
24 getDefaultValue: function () { return new Demo.Program.A(); }
25 },
26 v: 0,
27 ctor: function () {
28 this.$initialize();
29 },
30 getHashCode: function () {
31 var h = Bridge.addHash([65, this.v]);
32 return h;
33 },
34 equals: function (o) {
35 if (!Bridge.is(o, Demo.Program.A)) {
36 return false;
37 }
38 return Bridge.equals(this.v, o.v);
39 },
40 $clone: function (to) {
41 var s = to || new Demo.Program.A();
42 s.v = this.v;
43 return s;
44 }
45 });
46 });
1 5

is/as

结果正确:1

容易引入JSB:1

 1 public class Program
2 {
3 class A{}
4 class B{}
5 static void Test(object obj)
6 {
7 Console.WriteLine((obj is A).ToString());
8 Console.WriteLine((obj is B).ToString());
9 Console.WriteLine(((obj as A) != null).ToString());
10 Console.WriteLine(((obj as B) != null).ToString());
11 }
12 public static void Main()
13 {
14 A a = new A();
15 Test(a);
16 }
17 }
 1 /**
2 * @compiler Bridge.NET 15.3.0
3 */
4 Bridge.assembly("Demo", function ($asm, globals) {
5 "use strict";
6
7 Bridge.define("Demo.Program", {
8 statics: {
9 test: function (obj) {
10 Bridge.Console.log(System.Boolean.toString((Bridge.is(obj, Demo.Program.A))));
11 Bridge.Console.log(System.Boolean.toString((Bridge.is(obj, Demo.Program.B))));
12 Bridge.Console.log(System.Boolean.toString(((Bridge.as(obj, Demo.Program.A)) != null)));
13 Bridge.Console.log(System.Boolean.toString(((Bridge.as(obj, Demo.Program.B)) != null)));
14 }
15 },
16 $main: function () {
17 var a = new Demo.Program.A();
18 Demo.Program.test(a);
19 }
20 });
21
22 Bridge.define("Demo.Program.A");
23
24 Bridge.define("Demo.Program.B");
25 });
1 True
2 False
3 True
4 False

协程

结果正确:0

容易引入JSB:0

 1 public class Program
2 {
3 static IEnumerator Test()
4 {
5 yield return 100;
6 Console.WriteLine(1);
7 yield return 200;
8 Console.WriteLine(2);
9 yield return 300;
10 Console.WriteLine(3);
11 yield return 400;
12 Console.WriteLine(4);
13 }
14 public static void Main()
15 {
16 IEnumerator ie = Test();
17 while (ie.MoveNext())
18 {
19 Console.WriteLine("Current = " + ie.Current);
20 }
21 }
22 }
 1 /**
2 * @compiler Bridge.NET 15.3.0
3 */
4 Bridge.assembly("Demo", function ($asm, globals) {
5 "use strict";
6
7 Bridge.define("Demo.Program", {
8 statics: {
9 test: function () {
10 var $yield = [];
11 $yield.push(100);
12 Bridge.Console.log(1);
13 $yield.push(200);
14 Bridge.Console.log(2);
15 $yield.push(300);
16 Bridge.Console.log(3);
17 $yield.push(400);
18 Bridge.Console.log(4);
19 return System.Array.toEnumerator($yield);
20 }
21 },
22 $main: function () {
23 var ie = Demo.Program.test();
24 while (ie.System$Collections$IEnumerator$moveNext()) {
25 Bridge.Console.log(System.String.concat("Current = ", ie.System$Collections$IEnumerator$getCurrent()));
26 }
27 }
28 });
29 });
 1 // 错误输出!
2
3 1
4 2
5 3
6 4
7 Current = 100
8 Current = 200
9 Current = 300
10 Current = 400
 1 // 正确输出!
2
3 Current = 100
4 1
5 Current = 200
6 2
7 Current = 300
8 3
9 Current = 400
10 4

抢救办法(同当前JSB的做法):

 1 Bridge = {
2 Console: {
3 log: function (msg) {
4 print(msg);
5 }
6 }
7 }
8
9 var statics = {
10 test: function* () {
11
12 yield (100);
13 Bridge.Console.log(1);
14 yield (200);
15 Bridge.Console.log(2);
16 yield (300);
17 Bridge.Console.log(3);
18 yield (400);
19 Bridge.Console.log(4);
20
21 }
22 };
23
24 var p = statics.test();
25 while (true) {
26 var obj = p.next();
27 if (obj.done) {
28 break;
29 }
30 print(obj.value);
31 }

泛型

64位整数

结果正确:1

容易引入JSB:? 可能需要包装成字符串

1 public class Program
2 {
3 public static void Main()
4 {
5 long l = 1152921504606846976L;
6 Console.WriteLine(l.ToString());
7 }
8 }
 1 /**
2 * @compiler Bridge.NET 15.3.0
3 */
4 Bridge.assembly("Demo", function ($asm, globals) {
5 "use strict";
6
7 Bridge.define("Demo.Program", {
8 $main: function () {
9 var l = System.Int64([0,268435456]);
10 Bridge.Console.log(l.toString());
11 }
12 });
13 });
1 1152921504606846976

编译时能否引用其他dll

可以吗:不可以,跟 duocode 一样

可以处理吗?可以,给 UnityEngine.dll 做壳

Bridge默认把函数名首字母改成了小写

可以处理吗?可以,bridge.json 里加入 "preserveMemberCase": true

Bridge.js里有一些跟浏览器相关的代码

搜索 navigator

todo

需要判断Bridge.js已经支持哪些类,如果他已经支持,需要可以选择使用c#版还是使用js版

todo

// finish list

property命名:getXXX, setXXX

泛型函数后缀:无(sharpkit后缀$1 $2)

泛型函数泛型参数:放前面传进去(跟sharpkit一样)

泛型函数类型传递给C#:Bridge.Reflection.getTypeFullName(t0)

params处理:无需处理,他自己传递了数组

Indexer:getItem 或 getItem$1 或 getItem$2

Operator:一样

继承格式

interface

导出枚举

暂时去掉JS Vector2 Vector3 Vector4 实现

inherits 如果是 System.Object,忽略

field get/set 处理
JSGenerator 里 lstNames 是什么 用于输出都导出哪些了。删了
cs导出,参数是数组,代码不好看

IsInheritanceRel

64位整数拆分

JSBindingSettings放到editor下
导出的类和Bridge已有的类 2者的关系如何处理?--如果bridge有,就不能导出
协程
导出System.DateTime不行,因为他的interface找不到 - it'ok
Bridge工程生成js文件有一部分是不要的,如何去除?--csw.cs, csw.js
hashtable 导出后,加载 Gen1 发生错误--ok,排序有问题,interface排到hashtable后面去了

结构体问题:Bridge对结构体参数会先$clone一份,我们的处理是,对于导出的结构体,不要$clone,即$clone简单返回this。

// ignore list

生成的外壳代码需要加sealed(除了MonoBehaviour 和 interface)

不支持yield break

// todo list

System.Object UnityEngine.Object js Object

Cs 导出后一些 Manual-JS - 没处理完全

Bridge.assembly要看js代码,是否需要?

Bridge.assembly("Demo1", function ($asm, globals) {........});

Bridge 的匿名函数处理好像很奇怪?

jscomponent 怎么处理

// 测试列表

协程 ok

静态构造函数 ok

http://www.cnblogs.com/answerwinner/p/4478735.html 中第17条 ok

泛型类、泛型函数 ok

js List 试用 ok

js 使用 c# 带 ref/out 参数的函数 ok

js 使用 c# 带 params 参数的函数

// 特殊

1. 如果在Bridge工程添加文件,之后需要手动把对System.dll的引用去掉

2.

Bridge.NET的更多相关文章

  1. PHP设计模式(八)桥接模式(Bridge For PHP)

    一.概述 桥接模式:将两个原本不相关的类结合在一起,然后利用两个类中的方法和属性,输出一份新的结果. 二.案例 1.模拟毛笔(转) 需求:现在需要准备三种粗细(大中小),并且有五种颜色的比 如果使用蜡 ...

  2. Configure a bridge interface over a VLAN tagged bonded interface

    SOLUTION VERIFIED February 5 2014 KB340153 Environment Red Hat Enterprise Linux 6 (All Versions) Red ...

  3. Create a bridge using a tagged vlan (8021.q) interface

    SOLUTION VERIFIED April 27 2013 KB26727 Environment Red Hat Enterprise Linux 5 Red Hat Enterprise Li ...

  4. Configure bridge on a team interface using NetworkManager in RHEL 7

    SOLUTION IN PROGRESS February 29 2016 KB2181361 environment Red Hat Enterprise Linux 7 Teaming,Bridg ...

  5. 理解 neutron(15):Neutron linux-bridge-agent 创建 linux bridge 的简要过程

    学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...

  6. KVM 虚拟机联网方式:NAT 和 Bridge

    KVM 客户机网络连接有两种方式: 用户网络(User Networking):让虚拟机访问主机.互联网或本地网络上的资源的简单方法,但是不能从网络或其他的客户机访问客户机,性能上也需要大的调整.NA ...

  7. 桥接模式/bridge模式/对象结构型

    意图 将抽象部分与它的实现部分分离,使它们都可以独立的变化. 动机 当一个抽象类有多个实现时,通常用继承来协调它们.但是继承机制将抽象和实现固定,难以对抽象部分和实现部分独立地进行修改.扩充和重用. ...

  8. The network bridge on device VMnet0 is not running

    The network bridge on device VMnet0 is not running. The virtual machine will not be able to communic ...

  9. Net设计模式实例之桥接模式( Bridge Pattern)

    一.桥接模式简介(Brief Introduction) 桥接模式(Bridge Pattern),将抽象部分与它的实现部分分离,使的抽象和实现都可以独立地变化. Decouple an abstra ...

  10. Neutron 理解(14):Neutron ML2 + Linux bridge + VxLAN 组网

    学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...

随机推荐

  1. DOM位置参数

    以chrome浏览器测试为准 scrollwidth scrollheight clientwidth clientheight offsetwidth offsetheight 对象的实际宽高 包括 ...

  2. HBase的基本架构及其原理介绍

    1.概述:最近,有一些工程师问我有关HBase的基本架构的问题,其实这个问题仅仅说架构是非常简单,但是需要理解.在这里,我觉得可以用HDFS的架构作为借鉴.(其实像Hadoop生态系统中的大部分组建的 ...

  3. Java中静态内部类的理解

    class A { public void func() { A a=new A(); C c=a.new C(); } public static void main(String[] args) ...

  4. Why sql is called structured query language?1 - 12

    SQL has much to do with a researcher at IBM, Edgar F. (Ted) Codd, an Oxford-trained mathematician, w ...

  5. jdk 编译器 对final字段的处理

    class FinalTest{     void a(){         final int i=10;         int j=10;     } }            stack=2, ...

  6. 初学My Batis之入门

    MyBatis(百度百科): 下面我们来做第一个入门案例: 架构: jar包: 我们创建一个学生实体类 package cn.entity; /** * 学生实体类 * @author hyj * * ...

  7. 在VS的EF中连接MySQL

    VS没有主动提供那些繁多的连接器,需要的话得自己再安装这些第三方程序包. MySQL为windows平台开发者提供了许多程序包:http://dev.mysql.com/downloads/windo ...

  8. POJ 2976

    http://poj.org/problem?id=2976 01分数规划问题,可以舍掉k组 01分数规划用于解决的经典问题是最优比率生成树 解法见http://www.cnblogs.com/lot ...

  9. 烧写ARM开发板系统教程----->uboot 、内核以及文件系统

    一.sd启动 将u-boot镜像写入SD卡,将SD卡通过读卡器接上电脑(或直接插入笔记本卡槽),通过"cat /proc/partitions"找出SD卡对应的设备,我的设备节点是 ...

  10. 解析C#开发过程常见的编程模式

    单例模式: 在多线程的程序开发过程中经常会遇到单例模式[单件模式],它的特点是不是根据客户程序的调用而生成新的实例,而是控制某个类型的实例数量只有一个.也就是说,单例模式就是保证在整个应用程序的生命周 ...