Esempio n. 1
0
        public Task <SyntaxList <MemberDeclarationSyntax> > GenerateAsync(TransformationContext context, IProgress <Diagnostic> progress, CancellationToken cancellationToken)
        {
            var generatedMembers = SyntaxFactory.List <MemberDeclarationSyntax>();

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

            IEnumerable <MemberDeclarationSyntax> GenerateRecordPartials(RecordDescriptor descriptor)
            {
                yield return(RecordPartialGenerator.Generate(descriptor, cancellationToken));

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

                yield return(DeconstructPartialGenerator.Generate(descriptor, cancellationToken));

                yield break;
            }
        }
        public static TypeDeclarationSyntax Generate(RecordDescriptor descriptor, CancellationToken cancellationToken)
        {
            var generator = new DeconstructPartialGenerator(descriptor, cancellationToken);

            return(generator.GenerateTypeDeclaration());
        }