@@ -860,18 +860,28 @@ protected IReadOnlyList<MemberDeclarationSyntax> CreateMutableProperties()
860
860
861
861
protected MethodDeclarationSyntax CreateToImmutableMethod ( )
862
862
{
863
- // return this.immutable = this.immutable.With(...)
863
+ ExpressionSyntax returnExpression ;
864
+ if ( this . generator . applyToMetaType . AllFields . Any ( ) )
865
+ {
866
+ // this.immutable = this.immutable.With(...)
867
+ returnExpression = SyntaxFactory . AssignmentExpression (
868
+ SyntaxKind . SimpleAssignmentExpression ,
869
+ Syntax . ThisDot ( ImmutableFieldName ) ,
870
+ SyntaxFactory . InvocationExpression (
871
+ SyntaxFactory . MemberAccessExpression (
872
+ SyntaxKind . SimpleMemberAccessExpression ,
873
+ Syntax . ThisDot ( ImmutableFieldName ) ,
874
+ WithMethodName ) ,
875
+ this . generator . CreateArgumentList ( this . generator . applyToMetaType . AllFields , ArgSource . Property , OptionalStyle . Always ) ) ) ;
876
+ }
877
+ else
878
+ {
879
+ // this.immutable
880
+ returnExpression = Syntax . ThisDot ( ImmutableFieldName ) ;
881
+ }
882
+
864
883
var body = SyntaxFactory . Block (
865
- SyntaxFactory . ReturnStatement (
866
- SyntaxFactory . AssignmentExpression (
867
- SyntaxKind . SimpleAssignmentExpression ,
868
- Syntax . ThisDot ( ImmutableFieldName ) ,
869
- SyntaxFactory . InvocationExpression (
870
- SyntaxFactory . MemberAccessExpression (
871
- SyntaxKind . SimpleMemberAccessExpression ,
872
- Syntax . ThisDot ( ImmutableFieldName ) ,
873
- WithMethodName ) ,
874
- this . generator . CreateArgumentList ( this . generator . applyToMetaType . AllFields , ArgSource . Property , OptionalStyle . Always ) ) ) ) ) ;
884
+ SyntaxFactory . ReturnStatement ( returnExpression ) ) ;
875
885
876
886
// public TemplateType ToImmutable() { ... }
877
887
var method = SyntaxFactory . MethodDeclaration (
0 commit comments