All checks were successful
Run the JSON parser tests / test (push) Has been skipped
38 lines
1.2 KiB
C#
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()
|
|
);
|
|
}
|
|
} |