Skip to content

Commit 29f94a4

Browse files
committed
Rename [NotifyDataErrorInfo] attribute
1 parent 91a7798 commit 29f94a4

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/Models/PropertyInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace CommunityToolkit.Mvvm.SourceGenerators.ComponentModel.Models;
2121
/// <param name="PropertyChangedNames">The sequence of property changed properties to notify.</param>
2222
/// <param name="NotifiedCommandNames">The sequence of commands to notify.</param>
2323
/// <param name="AlsoBroadcastChange">Whether or not the generated property also broadcasts changes.</param>
24-
/// <param name="AlsoValidateProperty">Whether or not the generated property also validates its value.</param>
24+
/// <param name="NotifyDataErrorInfo">Whether or not the generated property also validates its value.</param>
2525
/// <param name="ForwardedAttributes">The sequence of forwarded attributes for the generated property.</param>
2626
internal sealed record PropertyInfo(
2727
string TypeNameWithNullabilityAnnotations,
@@ -31,7 +31,7 @@ internal sealed record PropertyInfo(
3131
ImmutableArray<string> PropertyChangedNames,
3232
ImmutableArray<string> NotifiedCommandNames,
3333
bool AlsoBroadcastChange,
34-
bool AlsoValidateProperty,
34+
bool NotifyDataErrorInfo,
3535
ImmutableArray<AttributeInfo> ForwardedAttributes)
3636
{
3737
/// <summary>
@@ -49,7 +49,7 @@ protected override void AddToHashCode(ref HashCode hashCode, PropertyInfo obj)
4949
hashCode.AddRange(obj.PropertyChangedNames);
5050
hashCode.AddRange(obj.NotifiedCommandNames);
5151
hashCode.Add(obj.AlsoBroadcastChange);
52-
hashCode.Add(obj.AlsoValidateProperty);
52+
hashCode.Add(obj.NotifyDataErrorInfo);
5353
hashCode.AddRange(obj.ForwardedAttributes, AttributeInfo.Comparer.Default);
5454
}
5555

@@ -64,7 +64,7 @@ protected override bool AreEqual(PropertyInfo x, PropertyInfo y)
6464
x.PropertyChangedNames.SequenceEqual(y.PropertyChangedNames) &&
6565
x.NotifiedCommandNames.SequenceEqual(y.NotifiedCommandNames) &&
6666
x.AlsoBroadcastChange == y.AlsoBroadcastChange &&
67-
x.AlsoValidateProperty == y.AlsoValidateProperty &&
67+
x.NotifyDataErrorInfo == y.NotifyDataErrorInfo &&
6868
x.ForwardedAttributes.SequenceEqual(y.ForwardedAttributes, AttributeInfo.Comparer.Default);
6969
}
7070
}

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/ObservablePropertyGenerator.Execute.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ internal static class Execute
168168
if (alsoValidateProperty && !hasAnyValidationAttributes)
169169
{
170170
builder.Add(
171-
MissingValidationAttributesForAlsoValidatePropertyError,
171+
MissingValidationAttributesForNotifyDataErrorInfoError,
172172
fieldSymbol,
173173
fieldSymbol.ContainingType,
174174
fieldSymbol.Name);
@@ -452,14 +452,14 @@ private static bool TryGetIsBroadcastingChanges(
452452
/// <param name="attributeData">The <see cref="AttributeData"/> instance for <paramref name="fieldSymbol"/>.</param>
453453
/// <param name="diagnostics">The current collection of gathered diagnostics.</param>
454454
/// <param name="isValidationTargetValid">Whether or not the the property is in a valid target that can validate values.</param>
455-
/// <returns>Whether or not the generated property for <paramref name="fieldSymbol"/> used <c>[AlsoValidateProperty]</c>.</returns>
455+
/// <returns>Whether or not the generated property for <paramref name="fieldSymbol"/> used <c>[NotifyDataErrorInfo]</c>.</returns>
456456
private static bool TryGetIsValidatingProperty(
457457
IFieldSymbol fieldSymbol,
458458
AttributeData attributeData,
459459
ImmutableArray<Diagnostic>.Builder diagnostics,
460460
out bool isValidationTargetValid)
461461
{
462-
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoValidatePropertyAttribute") == true)
462+
if (attributeData.AttributeClass?.HasFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyDataErrorInfoAttribute") == true)
463463
{
464464
// If the containing type is valid, track it
465465
if (fieldSymbol.ContainingType.InheritsFromFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservableValidator"))
@@ -471,7 +471,7 @@ private static bool TryGetIsValidatingProperty(
471471

472472
// Otherwise just emit the diagnostic and then ignore the attribute
473473
diagnostics.Add(
474-
MissingObservableValidatorInheritanceForAlsoValidatePropertyError,
474+
MissingObservableValidatorInheritanceForNotifyDataErrorInfoError,
475475
fieldSymbol,
476476
fieldSymbol.ContainingType,
477477
fieldSymbol.Name);
@@ -582,7 +582,7 @@ public static MemberDeclarationSyntax GetPropertySyntax(PropertyInfo propertyInf
582582
// If validation is requested, add a call to ValidateProperty:
583583
//
584584
// ValidateProperty(value, <PROPERTY_NAME>);
585-
if (propertyInfo.AlsoValidateProperty)
585+
if (propertyInfo.NotifyDataErrorInfo)
586586
{
587587
setterStatements.Add(
588588
ExpressionStatement(

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/ObservablePropertyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3838
fieldSymbols
3939
.Where(static item => item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute"));
4040

41-
// Get diagnostics for fields using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [AlsoValidateProperty], but not [ObservableProperty]
41+
// Get diagnostics for fields using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [NotifyDataErrorInfo], but not [ObservableProperty]
4242
IncrementalValuesProvider<Diagnostic> fieldSymbolsWithOrphanedDependentAttributeWithErrors =
4343
fieldSymbols
4444
.Where(static item =>
4545
(item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyPropertyChangedForAttribute") ||
4646
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyCanExecuteChangedForAttribute") ||
4747
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoBroadcastChangeAttribute") ||
48-
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.AlsoValidatePropertyAttribute")) &&
48+
item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.NotifyDataErrorInfoAttribute")) &&
4949
!item.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute"))
5050
.Select(static (item, _) => Execute.GetDiagnosticForFieldWithOrphanedDependentAttributes(item));
5151

CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,17 @@ internal static class DiagnosticDescriptors
319319
/// <summary>
320320
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when <c>[ObservableProperty]</c> is applied to a field in an invalid type.
321321
/// <para>
322-
/// Format: <c>"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [AlsoValidateProperty]"</c>.
322+
/// Format: <c>"The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [NotifyDataErrorInfo]"</c>.
323323
/// </para>
324324
/// </summary>
325325
public static readonly DiagnosticDescriptor FieldWithOrphanedDependentObservablePropertyAttributesError = new DiagnosticDescriptor(
326326
id: "MVVMTK0020",
327327
title: "Invalid use of attributes dependent on [ObservableProperty]",
328-
messageFormat: "The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [AlsoValidateProperty]",
328+
messageFormat: "The field {0}.{1} needs to be annotated with [ObservableProperty] in order to enable using [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [NotifyDataErrorInfo]",
329329
category: typeof(ObservablePropertyGenerator).FullName,
330330
defaultSeverity: DiagnosticSeverity.Error,
331331
isEnabledByDefault: true,
332-
description: "Fields not annotated with [ObservableProperty] cannot use [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [AlsoValidateProperty].",
332+
description: "Fields not annotated with [ObservableProperty] cannot use [NotifyPropertyChangedFor], [NotifyCanExecuteChangedFor], [AlsoBroadcastChange] and [NotifyDataErrorInfo].",
333333
helpLinkUri: "https://aka.ms/mvvmtoolkit");
334334

335335
/// <summary>
@@ -399,32 +399,32 @@ internal static class DiagnosticDescriptors
399399
/// <summary>
400400
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when the target type doesn't inherit from the <c>ObservableValidator</c> class.
401401
/// <para>
402-
/// Format: <c>"The field {0}.{1} cannot be annotated with [AlsoValidateProperty], as it is declared in a type that doesn't inherit from ObservableValidator"</c>.
402+
/// Format: <c>"The field {0}.{1} cannot be annotated with [NotifyDataErrorInfo], as it is declared in a type that doesn't inherit from ObservableValidator"</c>.
403403
/// </para>
404404
/// </summary>
405-
public static readonly DiagnosticDescriptor MissingObservableValidatorInheritanceForAlsoValidatePropertyError = new DiagnosticDescriptor(
405+
public static readonly DiagnosticDescriptor MissingObservableValidatorInheritanceForNotifyDataErrorInfoError = new DiagnosticDescriptor(
406406
id: "MVVMTK0025",
407407
title: "Missing ObservableValidator inheritance",
408-
messageFormat: "The field {0}.{1} cannot be annotated with [AlsoValidateProperty], as it is declared in a type that doesn't inherit from ObservableValidator",
408+
messageFormat: "The field {0}.{1} cannot be annotated with [NotifyDataErrorInfo], as it is declared in a type that doesn't inherit from ObservableValidator",
409409
category: typeof(ObservablePropertyGenerator).FullName,
410410
defaultSeverity: DiagnosticSeverity.Error,
411411
isEnabledByDefault: true,
412-
description: "Cannot apply [AlsoValidateProperty] to fields that are declared in a type that doesn't inherit from ObservableValidator.",
412+
description: "Cannot apply [NotifyDataErrorInfo] to fields that are declared in a type that doesn't inherit from ObservableValidator.",
413413
helpLinkUri: "https://aka.ms/mvvmtoolkit");
414414

415415
/// <summary>
416-
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when the target field uses [AlsoValidateProperty] but has no validation attributes.
416+
/// Gets a <see cref="DiagnosticDescriptor"/> indicating when the target field uses [NotifyDataErrorInfo] but has no validation attributes.
417417
/// <para>
418-
/// Format: <c>"The field {0}.{1} cannot be annotated with [AlsoValidateProperty], as it doesn't have any validation attributes to use during validation"</c>.
418+
/// Format: <c>"The field {0}.{1} cannot be annotated with [NotifyDataErrorInfo], as it doesn't have any validation attributes to use during validation"</c>.
419419
/// </para>
420420
/// </summary>
421-
public static readonly DiagnosticDescriptor MissingValidationAttributesForAlsoValidatePropertyError = new DiagnosticDescriptor(
421+
public static readonly DiagnosticDescriptor MissingValidationAttributesForNotifyDataErrorInfoError = new DiagnosticDescriptor(
422422
id: "MVVMTK0026",
423423
title: "Missing validation attributes",
424-
messageFormat: "The field {0}.{1} cannot be annotated with [AlsoValidateProperty], as it doesn't have any validation attributes to use during validation",
424+
messageFormat: "The field {0}.{1} cannot be annotated with [NotifyDataErrorInfo], as it doesn't have any validation attributes to use during validation",
425425
category: typeof(ObservablePropertyGenerator).FullName,
426426
defaultSeverity: DiagnosticSeverity.Error,
427427
isEnabledByDefault: true,
428-
description: "Cannot apply [AlsoValidateProperty] to fields that don't have any validation attributes to use during validation.",
428+
description: "Cannot apply [NotifyDataErrorInfo] to fields that don't have any validation attributes to use during validation.",
429429
helpLinkUri: "https://aka.ms/mvvmtoolkit");
430430
}

CommunityToolkit.Mvvm/ComponentModel/Attributes/AlsoValidatePropertyAttribute.cs renamed to CommunityToolkit.Mvvm/ComponentModel/Attributes/NotifyDataErrorInfoAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
1717
/// partial class MyViewModel : ObservableValidator
1818
/// {
1919
/// [ObservableProperty]
20-
/// [AlsoValidateProperty]
20+
/// [NotifyDataErrorInfo]
2121
/// [Required]
2222
/// [MinLength(2)]
2323
/// private string username;
@@ -39,6 +39,6 @@ namespace CommunityToolkit.Mvvm.ComponentModel;
3939
/// </code>
4040
/// </summary>
4141
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
42-
public sealed class AlsoValidatePropertyAttribute : Attribute
42+
public sealed class NotifyDataErrorInfoAttribute : Attribute
4343
{
4444
}

tests/CommunityToolkit.Mvvm.SourceGenerators.UnitTests/Test_SourceGeneratorsDiagnostics.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ public partial class MyViewModel : ObservableObject
12171217
}
12181218

12191219
[TestMethod]
1220-
public void MissingObservableValidatorInheritanceForAlsoValidatePropertyError()
1220+
public void MissingObservableValidatorInheritanceForNotifyDataErrorInfoError()
12211221
{
12221222
string source = @"
12231223
using System.ComponentModel.DataAnnotations;
@@ -1230,7 +1230,7 @@ public partial class SampleViewModel
12301230
{
12311231
[ObservableProperty]
12321232
[Required]
1233-
[AlsoValidateProperty]
1233+
[NotifyDataErrorInfo]
12341234
private string name;
12351235
}
12361236
}";
@@ -1239,7 +1239,7 @@ public partial class SampleViewModel
12391239
}
12401240

12411241
[TestMethod]
1242-
public void MissingValidationAttributesForAlsoValidatePropertyError()
1242+
public void MissingValidationAttributesForNotifyDataErrorInfoError()
12431243
{
12441244
string source = @"
12451245
using System.ComponentModel.DataAnnotations;
@@ -1250,7 +1250,7 @@ namespace MyApp
12501250
public partial class SampleViewModel : ObservableValidator
12511251
{
12521252
[ObservableProperty]
1253-
[AlsoValidateProperty]
1253+
[NotifyDataErrorInfo]
12541254
private string name;
12551255
}
12561256
}";

tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public void Test_ObservablePropertyWithValueNamedField_WithValidationAttributes(
232232

233233
Assert.AreEqual(model.Value, "Hello world");
234234

235-
// The [AlsoValidateProperty] attribute wasn't used, so the property shouldn't be validated
235+
// The [NotifyDataErrorInfo] attribute wasn't used, so the property shouldn't be validated
236236
Assert.IsFalse(errorsChanged);
237237

238238
CollectionAssert.AreEqual(new[] { nameof(model.Value) }, propertyNames);
@@ -965,7 +965,7 @@ public partial class ModelWithValuePropertyWithAutomaticValidation : ObservableV
965965
[ObservableProperty]
966966
[Required]
967967
[MinLength(5)]
968-
[AlsoValidateProperty]
968+
[NotifyDataErrorInfo]
969969
private string? value;
970970
}
971971

0 commit comments

Comments
 (0)