[C#] support Object API (#5710)

* [C#] support Object API

* fix sign-compare

* fix indent

* add new line before for loop.

* using auto whenever possible

* reduce the amout of blank lines.

* wip: support vectors of union

* done: support unions of vectors

* set C# version to 4.0
* remove null propagation operator
* remove auto property initializer
* remove expression-bodied method
* remove pattern matching

* add Example2 to NetTest.sh

* separate JavaUsage.md and CsharpUsage.md from JavaCsharpUsage.md

* add C# Object based API notes.

* support vs2010.

* remove range based for loop.

* remove System.Linq

* fix indent

* CreateSharedString to CreateString

* check shared attribute

* snake case
This commit is contained in:
mugisoba
2020-01-31 03:18:28 +09:00
committed by GitHub
parent c580fa284c
commit 7418d85872
36 changed files with 2548 additions and 107 deletions

View File

@@ -6,6 +6,7 @@ namespace MyGame.Example
{
using global::System;
using global::System.Collections.Generic;
using global::FlatBuffers;
public struct ArrayStruct : IFlatbufferObject
@@ -56,7 +57,66 @@ public struct ArrayStruct : IFlatbufferObject
builder.PutFloat(A);
return new Offset<MyGame.Example.ArrayStruct>(builder.Offset);
}
public ArrayStructT UnPack() {
var _o = new ArrayStructT();
this.UnPackTo(_o);
return _o;
}
public void UnPackTo(ArrayStructT _o) {
_o.A = this.A;
_o.B = new int[15];
for (var _j = 0; _j < 15; ++_j) { _o.B[_j] = this.B(_j); }
_o.C = this.C;
_o.D = new MyGame.Example.NestedStructT[2];
for (var _j = 0; _j < 2; ++_j) { _o.D[_j] = this.D(_j).UnPack(); }
_o.E = this.E;
_o.F = new long[2];
for (var _j = 0; _j < 2; ++_j) { _o.F[_j] = this.F(_j); }
}
public static Offset<MyGame.Example.ArrayStruct> Pack(FlatBufferBuilder builder, ArrayStructT _o) {
if (_o == null) return default(Offset<MyGame.Example.ArrayStruct>);
var _b = _o.B;
var _d_a = new int[2,2];
for (var idx0 = 0; idx0 < 2; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_d_a[idx0,idx1] = _o.D[idx0].A[idx1];}}
var _d_b = new MyGame.Example.TestEnum[2];
for (var idx0 = 0; idx0 < 2; ++idx0) {_d_b[idx0] = _o.D[idx0].B;}
var _d_c = new MyGame.Example.TestEnum[2,2];
for (var idx0 = 0; idx0 < 2; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_d_c[idx0,idx1] = _o.D[idx0].C[idx1];}}
var _d_d = new long[2,2];
for (var idx0 = 0; idx0 < 2; ++idx0) {for (var idx1 = 0; idx1 < 2; ++idx1) {_d_d[idx0,idx1] = _o.D[idx0].D[idx1];}}
var _f = _o.F;
return CreateArrayStruct(
builder,
_o.A,
_b,
_o.C,
_d_a,
_d_b,
_d_c,
_d_d,
_o.E,
_f);
}
};
public class ArrayStructT
{
public float A { get; set; }
public int[] B { get; set; }
public sbyte C { get; set; }
public MyGame.Example.NestedStructT[] D { get; set; }
public int E { get; set; }
public long[] F { get; set; }
public ArrayStructT() {
this.A = 0.0f;
this.B = new int[15];
this.C = 0;
this.D = new MyGame.Example.NestedStructT[2];
this.E = 0;
this.F = new long[2];
}
}
}