mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 07:06:26 +00:00
Union accessors in C# should use generic type for the table
When accessing a union field, we should return the same object type as was given to the method, i.e. the parameter should have a generic type for any Table-derived type. This way, we do not need to make superfluous casts (which also reduce type safety) like var myUnionType = (MyUnionType)buff.GetUnionField(new MyUnionType()); when we can do just var myUnionType = buff.GetUnionField(new MyUnionType()); Change-Id: Idac1b638e46cc50b1f2dc19f10741481202b1515
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
f7d24f60a2
commit
221193eaa2
@@ -20,7 +20,7 @@ public sealed class Monster : Table {
|
||||
public int InventoryLength { get { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; } }
|
||||
public Color Color { get { int o = __offset(16); return o != 0 ? (Color)bb.GetSbyte(o + bb_pos) : (Color)8; } }
|
||||
public Any TestType { get { int o = __offset(18); return o != 0 ? (Any)bb.Get(o + bb_pos) : (Any)0; } }
|
||||
public Table GetTest(Table obj) { int o = __offset(20); return o != 0 ? __union(obj, o) : null; }
|
||||
public TTable GetTest<TTable>(TTable obj) where TTable : Table { int o = __offset(20); return o != 0 ? __union(obj, o) : null; }
|
||||
public Test GetTest4(int j) { return GetTest4(new Test(), j); }
|
||||
public Test GetTest4(Test obj, int j) { int o = __offset(22); return o != 0 ? obj.__init(__vector(o) + j * 4, bb) : null; }
|
||||
public int Test4Length { get { int o = __offset(22); return o != 0 ? __vector_len(o) : 0; } }
|
||||
|
||||
Reference in New Issue
Block a user