jtr/Jtr.Tools/Json2CSharpTranslator.ClassTranslation.cs
mdnapo 96c203f842
All checks were successful
Run the JSON parser tests / test (push) Has been skipped
Moved UI to separate project, added Dockerfile & renamed project
2024-10-19 12:04:40 +02:00

31 lines
891 B
C#

using Humanizer;
namespace Jtr.Tools;
public static partial class Json2CSharpTranslator
{
public readonly struct ClassTranslation : ITranslation
{
public string Name { get; init; }
public List<PropertyTranslation> Properties { get; init; }
public void Translate(Context context)
{
context.Builder.Append($"public class {Name.Pascalize()}\n");
context.Builder.Append("{\n");
if (Properties.Count != 0)
{
var last = Properties.Last();
foreach (var property in Properties)
{
property.Translate(context);
context.Builder.Append(property.Equals(last) ? string.Empty : "\n");
}
}
context.Builder.Append("}\n\n");
}
}
}