29 lines
857 B
C#
29 lines
857 B
C#
using Humanizer;
|
|
|
|
namespace DevDisciples.Json.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)
|
|
{
|
|
if (Properties.Count == 0) return;
|
|
|
|
context.Builder.Append($"public class {Name.Pascalize()}\n");
|
|
context.Builder.Append("{\n");
|
|
|
|
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");
|
|
}
|
|
}
|
|
} |