mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-23 17:10:01 +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:
@@ -13,5 +13,29 @@ public enum AnyAmbiguousAliases : byte
|
||||
M3 = 3,
|
||||
};
|
||||
|
||||
public class AnyAmbiguousAliasesUnion {
|
||||
public AnyAmbiguousAliases Type { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public AnyAmbiguousAliasesUnion() {
|
||||
this.Type = AnyAmbiguousAliases.NONE;
|
||||
this.Value = null;
|
||||
}
|
||||
|
||||
public T As<T>() where T : class { return this.Value as T; }
|
||||
public MyGame.Example.MonsterT AsM1() { return this.As<MyGame.Example.MonsterT>(); }
|
||||
public MyGame.Example.MonsterT AsM2() { return this.As<MyGame.Example.MonsterT>(); }
|
||||
public MyGame.Example.MonsterT AsM3() { return this.As<MyGame.Example.MonsterT>(); }
|
||||
|
||||
public static int Pack(FlatBuffers.FlatBufferBuilder builder, AnyAmbiguousAliasesUnion _o) {
|
||||
switch (_o.Type) {
|
||||
default: return 0;
|
||||
case AnyAmbiguousAliases.M1: return MyGame.Example.Monster.Pack(builder, _o.AsM1()).Value;
|
||||
case AnyAmbiguousAliases.M2: return MyGame.Example.Monster.Pack(builder, _o.AsM2()).Value;
|
||||
case AnyAmbiguousAliases.M3: return MyGame.Example.Monster.Pack(builder, _o.AsM3()).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user