protected MethodDeclarationSyntax MutatorFrom(RecordEntry entry) { var arguments = RecordProperties.Select(x => { return(SyntaxFactory.Argument( SyntaxFactory.IdentifierName(x.Identifier))); }); var mutator = SyntaxFactory.MethodDeclaration(RecordTypeSyntax, MutatorIdentifierFor(entry)) .WithModifiers( SyntaxFactory.TokenList( SyntaxFactory.Token(SyntaxKind.PublicKeyword))) .WithParameterList( SyntaxFactory.ParameterList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Parameter( entry.Identifier) .WithType(entry.Type)))) .WithBody( SyntaxFactory.Block( SyntaxFactory.ReturnStatement( SyntaxFactory.ObjectCreationExpression(RecordTypeSyntax) .WithArgumentList( SyntaxFactory.ArgumentList( SyntaxFactory.SeparatedList(arguments)))))); return(mutator); }
protected SyntaxList <MemberDeclarationSyntax> GenerateMembers(SyntaxToken identifier, IReadOnlyList <RecordEntry> properties) { var ctor = SyntaxFactory.ConstructorDeclaration(identifier.ValueText) .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(RecordAttribute.GetPrimaryCtorAccessSyntaxKind()))) .WithParameterList(properties.IntoCtorParameterList()) .WithBody(properties.IntoCtorBody()); var members = SyntaxFactory.SingletonList <MemberDeclarationSyntax>(ctor); if (RecordAttribute.GetGenerateMutators()) { members = members.AddRange(RecordProperties.Select(p => MutatorFrom(p))); } return(members); }