Skip to content

Commit

Permalink
Do not cast default value to actual type in C#.
Browse files Browse the repository at this point in the history
  • Loading branch information
blep committed Oct 14, 2016
1 parent ec218a4 commit 1945e11
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/idl_gen_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,9 @@ void GenStruct(StructDef &struct_def, std::string *code_ptr) {
lang_.language == IDLOptions::kCSharp) {
code += ".Value";
}
code += ", " + SourceCastBasic(field.value.type);
code += ", ";
if (lang_.language == IDLOptions::kJava)
code += SourceCastBasic( field.value.type );
code += GenDefaultValue(field.value, false);
code += "); }\n";
if (field.value.type.base_type == BASE_TYPE_VECTOR) {
Expand Down
4 changes: 2 additions & 2 deletions tests/MyGame/Example/Monster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public struct Monster : IFlatbufferObject
public static void AddInventory(FlatBufferBuilder builder, VectorOffset inventoryOffset) { builder.AddOffset(5, inventoryOffset.Value, 0); }
public static VectorOffset CreateInventoryVector(FlatBufferBuilder builder, byte[] data) { builder.StartVector(1, data.Length, 1); for (int i = data.Length - 1; i >= 0; i--) builder.AddByte(data[i]); return builder.EndVector(); }
public static void StartInventoryVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(1, numElems, 1); }
public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(6, (sbyte)color, (sbyte)8); }
public static void AddTestType(FlatBufferBuilder builder, Any testType) { builder.AddByte(7, (byte)testType, (byte)0); }
public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(6, (sbyte)color, 8); }
public static void AddTestType(FlatBufferBuilder builder, Any testType) { builder.AddByte(7, (byte)testType, 0); }
public static void AddTest(FlatBufferBuilder builder, int testOffset) { builder.AddOffset(8, testOffset, 0); }
public static void AddTest4(FlatBufferBuilder builder, VectorOffset test4Offset) { builder.AddOffset(9, test4Offset.Value, 0); }
public static void StartTest4Vector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 2); }
Expand Down
2 changes: 1 addition & 1 deletion tests/MyGame/Example/TestSimpleTableWithEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static Offset<TestSimpleTableWithEnum> CreateTestSimpleTableWithEnum(Flat
}

public static void StartTestSimpleTableWithEnum(FlatBufferBuilder builder) { builder.StartObject(1); }
public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(0, (sbyte)color, (sbyte)2); }
public static void AddColor(FlatBufferBuilder builder, Color color) { builder.AddSbyte(0, (sbyte)color, 2); }
public static Offset<TestSimpleTableWithEnum> EndTestSimpleTableWithEnum(FlatBufferBuilder builder) {
int o = builder.EndObject();
return new Offset<TestSimpleTableWithEnum>(o);
Expand Down
2 changes: 1 addition & 1 deletion tests/namespace_test/NamespaceA/TableInFirstNS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct TableInFirstNS : IFlatbufferObject

public static void StartTableInFirstNS(FlatBufferBuilder builder) { builder.StartObject(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, (sbyte)0); }
public static void AddFooEnum(FlatBufferBuilder builder, NamespaceA.NamespaceB.EnumInNestedNS fooEnum) { builder.AddSbyte(1, (sbyte)fooEnum, 0); }
public static void AddFooStruct(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.StructInNestedNS> fooStructOffset) { builder.AddStruct(2, fooStructOffset.Value, 0); }
public static Offset<NamespaceA.TableInFirstNS> EndTableInFirstNS(FlatBufferBuilder builder) {
int o = builder.EndObject();
Expand Down

0 comments on commit 1945e11

Please sign in to comment.