Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

C# JS 交互处理

huliangjie edited this page Sep 3, 2020 · 6 revisions

ref/out 参数的处理

带 ref/out 参数的 C# 函数映射到 JS 函数时, 非out参数为 JS 传入参数, ref/out参数将于原返回值一起作为 JS object 返回.

static void foo(out int x, int y, out int z, ref int w) 
{
  x = 1;
  z = y;
  w = w + x;
}
// 对应 d.ts
// function foo(y: number, w: number): { x: number, z: number, w: number}

let { x, z, w } = foo(1, 2); // foo(y = 1, w = 2);
assert(x == 1);
// 或者 
let o = foo(1, 2);
print(o.x);

Nullable 处理

  • 可空类型对应 jsb.Nullable<T> (实际等价于非空类型声明)
Clone this wiki locally