You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Analyzers/WinRTRelayCommandIsNotGeneratedBindableCustomPropertyCompatibleAnalyzer.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ public override void Initialize(AnalysisContext context)
.WithOpenBracketToken(Token(TriviaList(Comment($"/// <summary>The backing field for <see cref=\"{commandInfo.PropertyName}\"/>.</summary>")),SyntaxKind.OpenBracketToken,TriviaList())))
228
-
.AddAttributeLists(forwardedFieldAttributes);
210
+
// Declare a backing field if needed
211
+
FieldDeclarationSyntax?fieldDeclaration=null;
212
+
if(commandInfo.FieldNameis not null)
213
+
{
214
+
// Construct the generated field as follows:
215
+
//
216
+
// /// <summary>The backing field for <see cref="<COMMAND_PROPERTY_NAME>"/></summary>
.WithOpenBracketToken(Token(TriviaList(Comment($"/// <summary>The backing field for <see cref=\"{commandInfo.PropertyName}\"/>.</summary>")),SyntaxKind.OpenBracketToken,TriviaList())))
232
+
.AddAttributeLists(forwardedFieldAttributes);
233
+
}
229
234
230
235
// Prepares the argument to pass the underlying method to invoke
string?cancelCommandFieldName=commandInfo.FieldNameis not null?$"{commandInfo.FieldName.Substring(0,commandInfo.FieldName.Length-"Command".Length)}CancelCommand":null;
.WithOpenBracketToken(Token(TriviaList(Comment($"/// <summary>The backing field for <see cref=\"{cancelCommandPropertyName}\"/>.</summary>")),SyntaxKind.OpenBracketToken,TriviaList())));
.WithOpenBracketToken(Token(TriviaList(Comment($"/// <summary>The backing field for <see cref=\"{cancelCommandPropertyName}\"/>.</summary>")),SyntaxKind.OpenBracketToken,TriviaList())));
377
+
378
+
}
369
379
370
380
// Construct the generated property as follows (the explicit delegate cast is needed to avoid overload resolution conflicts):
371
381
//
@@ -393,7 +403,7 @@ public static ImmutableArray<MemberDeclarationSyntax> GetSyntax(CommandInfo comm
393
403
ArrowExpressionClause(
394
404
AssignmentExpression(
395
405
SyntaxKind.CoalesceAssignmentExpression,
396
-
IdentifierName(cancelCommandFieldName),
406
+
cancelCommandFieldNameis not null?IdentifierName(cancelCommandFieldName):IdentifierName(Token(SyntaxKind.FieldKeyword)),
397
407
InvocationExpression(
398
408
MemberAccessExpression(
399
409
SyntaxKind.SimpleMemberAccessExpression,
@@ -402,10 +412,20 @@ public static ImmutableArray<MemberDeclarationSyntax> GetSyntax(CommandInfo comm
// We can use the field keyword as the generated field name if the language version is C# 14 or greater, or if it's C# 13 and the preview features are enabled.
525
+
// In this case, there is no need to generate a backing field, as the property itself will be auto-generated with an underlying field.
0 commit comments