Пример #1
0
        public Task <SyntaxList <MemberDeclarationSyntax> > GenerateAsync(TransformationContext context, IProgress <Diagnostic> progress, CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var templates = GetTemplateDescriptors().ToImmutableArray();

            var generatedMembers = SyntaxFactory.List <MemberDeclarationSyntax>();

            if (context.ProcessingNode is ClassDeclarationSyntax classDeclaration)
            {
                var descriptor = GetDescriptor(classDeclaration, templates);
                generatedMembers = generatedMembers.AddRange(GenerateRecordPartials(descriptor));
            }
            return(Task.FromResult(generatedMembers));

            IEnumerable <MemberDeclarationSyntax> GenerateRecordPartials(ModelDescriptor descriptor)
            {
                foreach (var transformedTemplate in ModelTemplateGenerator.Generate(descriptor, templates))
                {
                    yield return(transformedTemplate);
                }
                yield return(ModelPartialGenerator.Generate(descriptor, templates, cancellationToken));

                yield return(BuilderPartialGenerator.Generate(descriptor, templates, cancellationToken));

                yield return(DeconstructPartialGenerator.Generate(descriptor, templates, cancellationToken));
            }
        }
        public static TypeDeclarationSyntax Generate(ModelDescriptor descriptor, ImmutableArray <TemplateDescriptor> templateDescriptors, CancellationToken cancellationToken)
        {
            var generator = new DeconstructPartialGenerator(descriptor, templateDescriptors, cancellationToken);

            return(generator.GenerateTypeDeclaration());
        }