mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-20 06:05:05 +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.Example
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::FlatBuffers;
|
||||
|
||||
public struct Vec3 : IFlatbufferObject
|
||||
@@ -43,7 +44,51 @@ public struct Vec3 : IFlatbufferObject
|
||||
builder.PutFloat(X);
|
||||
return new Offset<MyGame.Example.Vec3>(builder.Offset);
|
||||
}
|
||||
public Vec3T UnPack() {
|
||||
var _o = new Vec3T();
|
||||
this.UnPackTo(_o);
|
||||
return _o;
|
||||
}
|
||||
public void UnPackTo(Vec3T _o) {
|
||||
_o.X = this.X;
|
||||
_o.Y = this.Y;
|
||||
_o.Z = this.Z;
|
||||
_o.Test1 = this.Test1;
|
||||
_o.Test2 = this.Test2;
|
||||
_o.Test3 = this.Test3.UnPack();
|
||||
}
|
||||
public static Offset<MyGame.Example.Vec3> Pack(FlatBufferBuilder builder, Vec3T _o) {
|
||||
if (_o == null) return default(Offset<MyGame.Example.Vec3>);
|
||||
return CreateVec3(
|
||||
builder,
|
||||
_o.X,
|
||||
_o.Y,
|
||||
_o.Z,
|
||||
_o.Test1,
|
||||
_o.Test2,
|
||||
_o.Test3.A,
|
||||
_o.Test3.B);
|
||||
}
|
||||
};
|
||||
|
||||
public class Vec3T
|
||||
{
|
||||
public float X { get; set; }
|
||||
public float Y { get; set; }
|
||||
public float Z { get; set; }
|
||||
public double Test1 { get; set; }
|
||||
public MyGame.Example.Color Test2 { get; set; }
|
||||
public MyGame.Example.TestT Test3 { get; set; }
|
||||
|
||||
public Vec3T() {
|
||||
this.X = 0.0f;
|
||||
this.Y = 0.0f;
|
||||
this.Z = 0.0f;
|
||||
this.Test1 = 0.0;
|
||||
this.Test2 = 0;
|
||||
this.Test3 = new MyGame.Example.TestT();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user