Skip to content

Commit b9e603f

Browse files
committed
[C#] Support DTO generation via system property.
Previously, you had to pass the `CSharpDtos` FQN as the `TargetCodeGenerator` when running sbe-tool; however, that means the XML schema was parsed multiple times, as DTOs depend on flyweights, which seems wasteful. Therefore, I have introduced a system property, `sbe.csharp.generate.dtos` that also controls the generation of DTOs when targetting `CSharp`.
1 parent 4832726 commit b9e603f

File tree

1 file changed

+18
-1
lines changed
  • sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp

1 file changed

+18
-1
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp/CSharp.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,28 @@
2525
*/
2626
public class CSharp implements TargetCodeGenerator
2727
{
28+
private static final boolean GENERATE_DTOS = Boolean.getBoolean("sbe.csharp.generate.dtos");
29+
2830
/**
2931
* {@inheritDoc}
3032
*/
3133
public CodeGenerator newInstance(final Ir ir, final String outputDir)
3234
{
33-
return new CSharpGenerator(ir, new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace()));
35+
final CSharpGenerator flyweightGenerator =
36+
new CSharpGenerator(ir, new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace()));
37+
38+
if (GENERATE_DTOS)
39+
{
40+
final CSharpDtoGenerator dtoGenerator =
41+
new CSharpDtoGenerator(ir, new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace()));
42+
43+
return () ->
44+
{
45+
flyweightGenerator.generate();
46+
dtoGenerator.generate();
47+
};
48+
}
49+
50+
return flyweightGenerator;
3451
}
3552
}

0 commit comments

Comments
 (0)