[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

@@ -13,3 +13,33 @@ public enum Character : byte
Unused = 6,
};
public class CharacterUnion {
public Character Type { get; set; }
public object Value { get; set; }
public CharacterUnion() {
this.Type = Character.NONE;
this.Value = null;
}
public T As<T>() where T : class { return this.Value as T; }
public AttackerT AsMuLan() { return this.As<AttackerT>(); }
public RapunzelT AsRapunzel() { return this.As<RapunzelT>(); }
public BookReaderT AsBelle() { return this.As<BookReaderT>(); }
public BookReaderT AsBookFan() { return this.As<BookReaderT>(); }
public string AsOther() { return this.As<string>(); }
public string AsUnused() { return this.As<string>(); }
public static int Pack(FlatBuffers.FlatBufferBuilder builder, CharacterUnion _o) {
switch (_o.Type) {
default: return 0;
case Character.MuLan: return Attacker.Pack(builder, _o.AsMuLan()).Value;
case Character.Rapunzel: return Rapunzel.Pack(builder, _o.AsRapunzel()).Value;
case Character.Belle: return BookReader.Pack(builder, _o.AsBelle()).Value;
case Character.BookFan: return BookReader.Pack(builder, _o.AsBookFan()).Value;
case Character.Other: return builder.CreateString(_o.AsOther()).Value;
case Character.Unused: return builder.CreateString(_o.AsUnused()).Value;
}
}
}