jtr/Jtr.Tools/Json2CSharpTranslator.Context.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

38 lines
1.2 KiB
C#

using System.Text;
using Humanizer;
namespace Jtr.Tools;
public static partial class Json2CSharpTranslator
{
public class Context
{
public enum TranslationScope
{
Array,
Object,
}
public const string DefaultRootClassName = "Root";
public const string DefaultNamespace = "My.Namespace";
public string RootClassName { get; init; } = DefaultRootClassName;
public string Namespace { get; init; } = DefaultNamespace;
public Stack<string> Name { get; init; } = new();
public Stack<ClassTranslation> Class { get; init; } = new();
public Stack<TranslationScope> Scope { get; init; } = new();
public List<ClassTranslation> Classes { get; } = new();
public readonly StringBuilder Builder = new();
public string CurrentClassName =>
string.Join(
string.Empty,
Class
.SkipLast(1)
.Select(cls => cls.Name.Pascalize().Singularize())
.Prepend(Name.Peek().Pascalize().Singularize())
.Reverse()
.ToArray()
);
}
}