mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 19:50:02 +00:00
[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:
@@ -6,6 +6,7 @@ namespace MyGame
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::FlatBuffers;
|
||||
|
||||
public struct MonsterExtra : IFlatbufferObject
|
||||
@@ -102,7 +103,78 @@ public struct MonsterExtra : IFlatbufferObject
|
||||
}
|
||||
public static void FinishMonsterExtraBuffer(FlatBufferBuilder builder, Offset<MyGame.MonsterExtra> offset) { builder.Finish(offset.Value, "MONE"); }
|
||||
public static void FinishSizePrefixedMonsterExtraBuffer(FlatBufferBuilder builder, Offset<MyGame.MonsterExtra> offset) { builder.FinishSizePrefixed(offset.Value, "MONE"); }
|
||||
public MonsterExtraT UnPack() {
|
||||
var _o = new MonsterExtraT();
|
||||
this.UnPackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void UnPackTo(MonsterExtraT _o) {
|
||||
_o.D0 = this.D0;
|
||||
_o.D1 = this.D1;
|
||||
_o.D2 = this.D2;
|
||||
_o.D3 = this.D3;
|
||||
_o.F0 = this.F0;
|
||||
_o.F1 = this.F1;
|
||||
_o.F2 = this.F2;
|
||||
_o.F3 = this.F3;
|
||||
_o.Dvec = new List<double>();
|
||||
for (var _j = 0; _j < this.DvecLength; ++_j) {_o.Dvec.Add(this.Dvec(_j));}
|
||||
_o.Fvec = new List<float>();
|
||||
for (var _j = 0; _j < this.FvecLength; ++_j) {_o.Fvec.Add(this.Fvec(_j));}
|
||||
}
|
||||
public static Offset<MyGame.MonsterExtra> Pack(FlatBufferBuilder builder, MonsterExtraT _o) {
|
||||
if (_o == null) return default(Offset<MyGame.MonsterExtra>);
|
||||
var _dvec = default(VectorOffset);
|
||||
if (_o.Dvec != null) {
|
||||
var __dvec = _o.Dvec.ToArray();
|
||||
_dvec = CreateDvecVector(builder, __dvec);
|
||||
}
|
||||
var _fvec = default(VectorOffset);
|
||||
if (_o.Fvec != null) {
|
||||
var __fvec = _o.Fvec.ToArray();
|
||||
_fvec = CreateFvecVector(builder, __fvec);
|
||||
}
|
||||
return CreateMonsterExtra(
|
||||
builder,
|
||||
_o.D0,
|
||||
_o.D1,
|
||||
_o.D2,
|
||||
_o.D3,
|
||||
_o.F0,
|
||||
_o.F1,
|
||||
_o.F2,
|
||||
_o.F3,
|
||||
_dvec,
|
||||
_fvec);
|
||||
}
|
||||
};
|
||||
|
||||
public class MonsterExtraT
|
||||
{
|
||||
public double D0 { get; set; }
|
||||
public double D1 { get; set; }
|
||||
public double D2 { get; set; }
|
||||
public double D3 { get; set; }
|
||||
public float F0 { get; set; }
|
||||
public float F1 { get; set; }
|
||||
public float F2 { get; set; }
|
||||
public float F3 { get; set; }
|
||||
public List<double> Dvec { get; set; }
|
||||
public List<float> Fvec { get; set; }
|
||||
|
||||
public MonsterExtraT() {
|
||||
this.D0 = Double.NaN;
|
||||
this.D1 = Double.NaN;
|
||||
this.D2 = Double.PositiveInfinity;
|
||||
this.D3 = Double.NegativeInfinity;
|
||||
this.F0 = Single.NaN;
|
||||
this.F1 = Single.NaN;
|
||||
this.F2 = Single.PositiveInfinity;
|
||||
this.F3 = Single.NegativeInfinity;
|
||||
this.Dvec = null;
|
||||
this.Fvec = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user