1 // <auto-generated> 2 // automatically generated by the FlatBuffers compiler, do not modify 3 // </auto-generated> 4 5 namespace MyGame.Example 6 { 7 8 [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 9 public enum Any : byte 10 { 11 NONE = 0, 12 Monster = 1, 13 TestSimpleTableWithEnum = 2, 14 MyGame_Example2_Monster = 3, 15 }; 16 17 public class AnyUnion { 18 public Any Type { get; set; } 19 public object Value { get; set; } 20 AnyUnion()21 public AnyUnion() { 22 this.Type = Any.NONE; 23 this.Value = null; 24 } 25 26 public T As<T>() where T : class { return this.Value as T; } AsMonster()27 public MyGame.Example.MonsterT AsMonster() { return this.As<MyGame.Example.MonsterT>(); } AsTestSimpleTableWithEnum()28 internal MyGame.Example.TestSimpleTableWithEnumT AsTestSimpleTableWithEnum() { return this.As<MyGame.Example.TestSimpleTableWithEnumT>(); } AsMyGame_Example2_Monster()29 public MyGame.Example2.MonsterT AsMyGame_Example2_Monster() { return this.As<MyGame.Example2.MonsterT>(); } 30 Pack(FlatBuffers.FlatBufferBuilder builder, AnyUnion _o)31 public static int Pack(FlatBuffers.FlatBufferBuilder builder, AnyUnion _o) { 32 switch (_o.Type) { 33 default: return 0; 34 case Any.Monster: return MyGame.Example.Monster.Pack(builder, _o.AsMonster()).Value; 35 case Any.TestSimpleTableWithEnum: return MyGame.Example.TestSimpleTableWithEnum.Pack(builder, _o.AsTestSimpleTableWithEnum()).Value; 36 case Any.MyGame_Example2_Monster: return MyGame.Example2.Monster.Pack(builder, _o.AsMyGame_Example2_Monster()).Value; 37 } 38 } 39 } 40 41 public class AnyUnion_JsonConverter : Newtonsoft.Json.JsonConverter { CanConvert(System.Type objectType)42 public override bool CanConvert(System.Type objectType) { 43 return objectType == typeof(AnyUnion) || objectType == typeof(System.Collections.Generic.List<AnyUnion>); 44 } WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)45 public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) { 46 var _olist = value as System.Collections.Generic.List<AnyUnion>; 47 if (_olist != null) { 48 writer.WriteStartArray(); 49 foreach (var _o in _olist) { this.WriteJson(writer, _o, serializer); } 50 writer.WriteEndArray(); 51 } else { 52 this.WriteJson(writer, value as AnyUnion, serializer); 53 } 54 } WriteJson(Newtonsoft.Json.JsonWriter writer, AnyUnion _o, Newtonsoft.Json.JsonSerializer serializer)55 public void WriteJson(Newtonsoft.Json.JsonWriter writer, AnyUnion _o, Newtonsoft.Json.JsonSerializer serializer) { 56 if (_o == null) return; 57 serializer.Serialize(writer, _o.Value); 58 } ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)59 public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) { 60 var _olist = existingValue as System.Collections.Generic.List<AnyUnion>; 61 if (_olist != null) { 62 for (var _j = 0; _j < _olist.Count; ++_j) { 63 reader.Read(); 64 _olist[_j] = this.ReadJson(reader, _olist[_j], serializer); 65 } 66 reader.Read(); 67 return _olist; 68 } else { 69 return this.ReadJson(reader, existingValue as AnyUnion, serializer); 70 } 71 } ReadJson(Newtonsoft.Json.JsonReader reader, AnyUnion _o, Newtonsoft.Json.JsonSerializer serializer)72 public AnyUnion ReadJson(Newtonsoft.Json.JsonReader reader, AnyUnion _o, Newtonsoft.Json.JsonSerializer serializer) { 73 if (_o == null) return null; 74 switch (_o.Type) { 75 default: break; 76 case Any.Monster: _o.Value = serializer.Deserialize<MyGame.Example.MonsterT>(reader); break; 77 case Any.TestSimpleTableWithEnum: _o.Value = serializer.Deserialize<MyGame.Example.TestSimpleTableWithEnumT>(reader); break; 78 case Any.MyGame_Example2_Monster: _o.Value = serializer.Deserialize<MyGame.Example2.MonsterT>(reader); break; 79 } 80 return _o; 81 } 82 } 83 84 85 } 86