Skip to content

Commit

Permalink
[C#] Support DTO generation via system property.
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ZachBray committed Oct 18, 2023
1 parent e2706cd commit f7bc822
Showing 1 changed file with 18 additions and 1 deletion.
Expand Up @@ -25,11 +25,28 @@
*/
public class CSharp implements TargetCodeGenerator
{
private static final boolean GENERATE_DTOS = Boolean.getBoolean("sbe.csharp.generate.dtos");

/**
* {@inheritDoc}
*/
public CodeGenerator newInstance(final Ir ir, final String outputDir)
{
return new CSharpGenerator(ir, new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace()));
final CSharpGenerator flyweightGenerator =
new CSharpGenerator(ir, new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace()));

if (GENERATE_DTOS)
{
final CSharpDtoGenerator dtoGenerator =
new CSharpDtoGenerator(ir, new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace()));

return () ->
{
flyweightGenerator.generate();
dtoGenerator.generate();
};
}

return flyweightGenerator;
}
}

0 comments on commit f7bc822

Please sign in to comment.