Skip to content

Commit 83bcc44

Browse files
Copilotdrewnoakes
andcommitted
Localize error messages for CompletedTaskAttribute validation
Co-authored-by: drewnoakes <[email protected]>
1 parent 9e2bda8 commit 83bcc44

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD003UseJtfRunAsyncAnalyzer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private void AnalyzeSymbolForInvalidAttributeUse(SymbolAnalysisContext context)
230230
// Fields must be readonly
231231
if (!fieldSymbol.IsReadOnly)
232232
{
233-
errorMessage = "Fields must be readonly.";
233+
errorMessage = Strings.VSTHRD003InvalidAttributeUse_FieldNotReadonly;
234234
}
235235
}
236236
else if (symbol is IPropertySymbol propertySymbol)
@@ -243,13 +243,13 @@ private void AnalyzeSymbolForInvalidAttributeUse(SymbolAnalysisContext context)
243243
{
244244
if (propertySymbol.DeclaredAccessibility != Accessibility.Private)
245245
{
246-
errorMessage = "Properties with init accessors must be private.";
246+
errorMessage = Strings.VSTHRD003InvalidAttributeUse_PropertyWithNonPrivateInit;
247247
}
248248
}
249249
else if (propertySymbol.SetMethod.DeclaredAccessibility != Accessibility.Private)
250250
{
251251
// Non-private setters are not allowed
252-
errorMessage = "Properties must not have non-private setters.";
252+
errorMessage = Strings.VSTHRD003InvalidAttributeUse_PropertyWithNonPrivateSetter;
253253
}
254254
}
255255
}

src/Microsoft.VisualStudio.Threading.Analyzers/Strings.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,16 @@ Start the work within this context, or use JoinableTaskFactory.RunAsync to start
359359
<data name="VSTHRD003InvalidAttributeUse_MessageFormat" xml:space="preserve">
360360
<value>CompletedTaskAttribute can only be applied to readonly fields, properties without non-private setters, or methods. {0}</value>
361361
</data>
362+
<data name="VSTHRD003InvalidAttributeUse_FieldNotReadonly" xml:space="preserve">
363+
<value>Fields must be readonly.</value>
364+
<comment>Error message shown when the CompletedTaskAttribute is applied to a field that is not marked as readonly. The attribute is only valid on readonly fields to ensure the task value cannot be changed.</comment>
365+
</data>
366+
<data name="VSTHRD003InvalidAttributeUse_PropertyWithNonPrivateSetter" xml:space="preserve">
367+
<value>Properties must not have non-private setters.</value>
368+
<comment>Error message shown when the CompletedTaskAttribute is applied to a property that has a public, internal, or protected setter. The attribute is only valid on properties with private setters or no setter (getter-only) to ensure the task value cannot be changed from outside the class.</comment>
369+
</data>
370+
<data name="VSTHRD003InvalidAttributeUse_PropertyWithNonPrivateInit" xml:space="preserve">
371+
<value>Properties with init accessors must be private.</value>
372+
<comment>Error message shown when the CompletedTaskAttribute is applied to a property with a public, internal, or protected init accessor. Init accessors allow setting the property during object initialization, so the property itself must be private when using this attribute to ensure the task value cannot be changed from outside the class.</comment>
373+
</data>
362374
</root>

0 commit comments

Comments
 (0)