diff options
author | stefan301 <32997632+stefan301@users.noreply.github.com> | 2020-03-23 17:39:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-23 09:39:26 -0700 |
commit | 3af73593453d70585542aad617f62e4f041b6ada (patch) | |
tree | b627b45f40df5caa2cdf9ca0ae27f33b9ea99d1f /tests/namespace_test | |
parent | c4231c3cb99159978ca5f0669a07ef1aa02b88e3 (diff) | |
download | flatbuffers-3af73593453d70585542aad617f62e4f041b6ada.tar.gz flatbuffers-3af73593453d70585542aad617f62e4f041b6ada.tar.bz2 flatbuffers-3af73593453d70585542aad617f62e4f041b6ada.zip |
[csharp] flatc should generate a 'Create…' method for tables with struct field… (#5818)
* flatc should generate a 'Create…' method for tables with struct fields when also generating the object based api (C#)
https://stackoverflow.com/questions/60724317/flatc-should-generate-a-create-method-for-tables-with-struct-fields-when-al
* missing namespace fixed: C:\projects\flatbuffers\tests\namespace_test\NamespaceA\TableInFirstNS.cs(30,7): error CS0246: The type or namespace name 'StructInNestedNST' could not be found (are you missing a using directive or an assembly reference?) [C:\projects\flatbuffers\tests\FlatBuffers.Test\FlatBuffers.Test.csproj]
Co-authored-by: stefan301 <Stefan.Felkel@de.Zuken.com>
Diffstat (limited to 'tests/namespace_test')
-rw-r--r-- | tests/namespace_test/NamespaceA/TableInFirstNS.cs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.cs b/tests/namespace_test/NamespaceA/TableInFirstNS.cs index 9c7be472..3d597d7f 100644 --- a/tests/namespace_test/NamespaceA/TableInFirstNS.cs +++ b/tests/namespace_test/NamespaceA/TableInFirstNS.cs @@ -24,6 +24,17 @@ public struct TableInFirstNS : IFlatbufferObject public bool MutateFooEnum(NamespaceA.NamespaceB.EnumInNestedNS foo_enum) { int o = __p.__offset(6); if (o != 0) { __p.bb.PutSbyte(o + __p.bb_pos, (sbyte)foo_enum); return true; } else { return false; } } public NamespaceA.NamespaceB.StructInNestedNS? FooStruct { get { int o = __p.__offset(8); return o != 0 ? (NamespaceA.NamespaceB.StructInNestedNS?)(new NamespaceA.NamespaceB.StructInNestedNS()).__assign(o + __p.bb_pos, __p.bb) : null; } } + public static Offset<NamespaceA.TableInFirstNS> CreateTableInFirstNS(FlatBufferBuilder builder, + Offset<NamespaceA.NamespaceB.TableInNestedNS> foo_tableOffset = default(Offset<NamespaceA.NamespaceB.TableInNestedNS>), + NamespaceA.NamespaceB.EnumInNestedNS foo_enum = NamespaceA.NamespaceB.EnumInNestedNS.A, + NamespaceA.NamespaceB.StructInNestedNST foo_struct = null) { + builder.StartTable(3); + TableInFirstNS.AddFooStruct(builder, NamespaceA.NamespaceB.StructInNestedNS.Pack(builder, foo_struct)); + TableInFirstNS.AddFooTable(builder, foo_tableOffset); + TableInFirstNS.AddFooEnum(builder, foo_enum); + return TableInFirstNS.EndTableInFirstNS(builder); + } + public static void StartTableInFirstNS(FlatBufferBuilder builder) { builder.StartTable(3); } public static void AddFooTable(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.TableInNestedNS> fooTableOffset) { builder.AddOffset(0, fooTableOffset.Value, 0); } public static void AddFooEnum(FlatBufferBuilder builder, NamespaceA.NamespaceB.EnumInNestedNS fooEnum) { builder.AddSbyte(1, (sbyte)fooEnum, 0); } @@ -45,11 +56,11 @@ public struct TableInFirstNS : IFlatbufferObject public static Offset<NamespaceA.TableInFirstNS> Pack(FlatBufferBuilder builder, TableInFirstNST _o) { if (_o == null) return default(Offset<NamespaceA.TableInFirstNS>); var _foo_table = _o.FooTable == null ? default(Offset<NamespaceA.NamespaceB.TableInNestedNS>) : NamespaceA.NamespaceB.TableInNestedNS.Pack(builder, _o.FooTable); - StartTableInFirstNS(builder); - AddFooTable(builder, _foo_table); - AddFooEnum(builder, _o.FooEnum); - AddFooStruct(builder, NamespaceA.NamespaceB.StructInNestedNS.Pack(builder, _o.FooStruct)); - return EndTableInFirstNS(builder); + return CreateTableInFirstNS( + builder, + _foo_table, + _o.FooEnum, + _o.FooStruct); } }; |