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)
@@ -135,6 +135,17 @@ public static bool TryGetInfo(
135
135
136
136
token.ThrowIfCancellationRequested();
137
137
138
+
// Get the option to force a backing field, if any
139
+
if(!TryGetUseBackingField(
140
+
attributeData,
141
+
semanticModel,
142
+
outbooluseBackingField))
143
+
{
144
+
gotoFailure;
145
+
}
146
+
147
+
token.ThrowIfCancellationRequested();
148
+
138
149
// Get all forwarded attributes (don't stop in case of errors, just ignore faulting attributes)
139
150
GatherForwardedAttributes(
140
151
methodSymbol,
@@ -147,7 +158,7 @@ public static bool TryGetInfo(
147
158
148
159
commandInfo=newCommandInfo(
149
160
methodSymbol.Name,
150
-
fieldName,
161
+
useBackingField?fieldName:null,
151
162
propertyName,
152
163
commandInterfaceType,
153
164
commandClassType,
@@ -356,8 +367,8 @@ public static ImmutableArray<MemberDeclarationSyntax> GetSyntax(CommandInfo comm
356
367
if(commandInfo.IncludeCancelCommand)
357
368
{
358
369
// Prepare all necessary member and type names
359
-
string?cancelCommandFieldName=commandInfo.FieldNameis not null?$"{commandInfo.FieldName.Substring(0,commandInfo.FieldName.Length-"Command".Length)}CancelCommand":null;
// 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.
523
-
// In this case, there is no need to generate a backing field, as the property itself will be auto-generated with an underlying field.
// We can only 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.
Copy file name to clipboardExpand all lines: src/CommunityToolkit.Mvvm/Input/Attributes/RelayCommandAttribute.cs
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -116,4 +116,9 @@ public sealed class RelayCommandAttribute : Attribute
116
116
/// </summary>
117
117
/// <remarks>Using this property is not valid if the target command doesn't map to a cancellable asynchronous command.</remarks>
118
118
publicboolIncludeCancelCommand{get;init;}
119
+
120
+
/// <summary>
121
+
/// Gets or sets a value indicating whether or not a backing field should generated regardless of the availablity of the <see langword="field"/> keyword.
0 commit comments