Feature summary
I've been hacking on my own fork of this for a month or two, with changes that mostly wouldn't be interesting to others. One change that I've found very valuable was adding an 'AppendBlock' method, which has made adding features to CSharpCodeEmitter quite a bit easier and more readable to me.
Rather than just using AppendLine and manually incrementing/decrementing the indent level, I added this method:
private void AppendBlock(string prefix, Action act)
{
AppendLine(prefix);
AppendLine("{");
_indent++;
act();
_indent--;
AppendLine("}");
}
With that method, my code for creating (for example) type alias jsonconverters looks like this, which I find much more readable because the indent nesting of the generator matches that of the generated code.
AppendBlock($"public class {converterName} : JsonConverter<{typeName}>", () =>
{
AppendBlock($"public override {typeName} Read(ref Utf8JsonReader reader, Type typeToConvert,JsonSerializerOptions options)",() =>
{
AppendLine($"return new {typeName}({readerWriterTypeName.read}!);");
});
AppendBlock($"public override void Write( Utf8JsonWriter writer, {typeName} value, JsonSerializerOptions options)",() =>
{
AppendLine($"writer.{readerWriterTypeName.write}(value.Value{readerWriterTypeName.writeModifier});");
});
});
Might not matter for you if you're mostly using LLM to write the code, but I found it useful since I'm mostly making changes by hand.
Additional details
No response
Feature summary
I've been hacking on my own fork of this for a month or two, with changes that mostly wouldn't be interesting to others. One change that I've found very valuable was adding an 'AppendBlock' method, which has made adding features to CSharpCodeEmitter quite a bit easier and more readable to me.
Rather than just using AppendLine and manually incrementing/decrementing the indent level, I added this method:
With that method, my code for creating (for example) type alias jsonconverters looks like this, which I find much more readable because the indent nesting of the generator matches that of the generated code.
Might not matter for you if you're mostly using LLM to write the code, but I found it useful since I'm mostly making changes by hand.
Additional details
No response