@@ -171,21 +171,29 @@ private static PropertyDeclarationSyntax CreatePropertyDeclaration(GeneratorExec
171171 {
172172 // Generate the inner setter block as follows:
173173 //
174+ // SetProperty(ref <FIELD_NAME>, value, true);
175+ //
176+ // Or in case there is at least one dependent property:
177+ //
174178 // if (SetProperty(ref <FIELD_NAME>, value, true))
175179 // {
176180 // OnPropertyChanged("Property1"); // Optional
177181 // OnPropertyChanged("Property2");
178182 // ...
179183 // OnPropertyChanged("PropertyN");
180184 // }
181- setterBlock = Block (
182- IfStatement (
183- InvocationExpression ( IdentifierName ( "SetProperty" ) )
184- . AddArgumentListArguments (
185- Argument ( IdentifierName ( fieldSymbol . Name ) ) . WithRefOrOutKeyword ( Token ( SyntaxKind . RefKeyword ) ) ,
186- Argument ( IdentifierName ( "value" ) ) ,
187- Argument ( LiteralExpression ( SyntaxKind . TrueLiteralExpression ) ) ) ,
188- Block ( dependentPropertyNotificationStatements ) ) ) ;
185+ InvocationExpressionSyntax setPropertyExpression =
186+ InvocationExpression ( IdentifierName ( "SetProperty" ) )
187+ . AddArgumentListArguments (
188+ Argument ( IdentifierName ( fieldSymbol . Name ) ) . WithRefOrOutKeyword ( Token ( SyntaxKind . RefKeyword ) ) ,
189+ Argument ( IdentifierName ( "value" ) ) ,
190+ Argument ( LiteralExpression ( SyntaxKind . TrueLiteralExpression ) ) ) ;
191+
192+ setterBlock = dependentPropertyNotificationStatements . Count switch
193+ {
194+ 0 => Block ( ExpressionStatement ( setPropertyExpression ) ) ,
195+ _ => Block ( IfStatement ( setPropertyExpression , Block ( dependentPropertyNotificationStatements ) ) )
196+ } ;
189197 }
190198 else
191199 {
0 commit comments