Exemplo n.º 1
0
        public GenerationResult GenerateSingleItem(GenerationProperties properties)
        {
            var result = GenerateInternal(properties);

            var nodes  = result.Classes.Select(x => x.SyntaxNode).Union(result.Enums.Select(x => x.SyntaxNode));
            var usings = result.Classes.SelectMany(x => x.Usings).Distinct();

            var code = GenerateSourceCodeString(usings, properties.NameSpace, nodes.ToArray());

            return(new GenerationResult
            {
                Code = code,
                FileName = "GeneratedClasses"
            });
        }
Exemplo n.º 2
0
        public IEnumerable <GenerationResult> GenerateSeparateItems(GenerationProperties properties)
        {
            var result = GenerateInternal(properties);

            var classes = result.Classes.Select(x => new GenerationResult
            {
                Code     = GenerateSourceCodeString(x.Usings, properties.NameSpace, x.SyntaxNode),
                FileName = x.Name
            });

            var enums = result.Enums.Select(x => new GenerationResult
            {
                Code     = GenerateSourceCodeString(new List <string>(), properties.NameSpace, x.SyntaxNode),
                FileName = x.Name
            });

            return(classes.Union(enums));
        }
Exemplo n.º 3
0
        private (IEnumerable <GeneratedItem> Enums, IEnumerable <GeneratedItem> Classes) GenerateInternal(GenerationProperties properties)
        {
            if (string.IsNullOrEmpty(properties.NameSpace))
            {
                throw new CodeGeneratorFailException(@"'NameSpace' should be determined.");
            }

            var schema = JSchema.Parse(properties.JsonSchema);

            var context = new GenerationContext(properties);

            BuildClassExpression(schema, context);

            context.GeneratedClasses.Reverse();

            var classes = DistinctDeclarations(context.GeneratedClasses);
            var enums   = DistinctDeclarations(context.GeneratedEnums);

            return(enums, classes);
        }
Exemplo n.º 4
0
 public GenerationContext(GenerationProperties properties)
 {
     IsSealed = properties.IsSealed;
 }