Skip to content

Commit a4d239e

Browse files
authored
Merge pull request #884 from arivoir/feature/881
Avoid auto-generating ObservableValidator.HasError
2 parents 19173a1 + a2daea9 commit a4d239e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/CommunityToolkit.Mvvm/ComponentModel/ObservableValidator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ protected ObservableValidator(ValidationContext validationContext)
123123
}
124124

125125
/// <inheritdoc/>
126+
[Display(AutoGenerateField = false)]
126127
public bool HasErrors => this.totalErrors > 0;
127128

128129
/// <summary>

tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservableValidator.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,20 @@ public void Test_ObservableValidator_ValidateAllProperties_IncludeInheritedPrope
607607
Assert.IsFalse(model.HasErrors);
608608
Assert.IsTrue(events.Count == 1);
609609

610-
Assert.IsTrue(events.Any(e => e.PropertyName == nameof(DerivedModelWithValidatableProperties.Name))); }
610+
Assert.IsTrue(events.Any(e => e.PropertyName == nameof(DerivedModelWithValidatableProperties.Name)));
611+
}
612+
613+
// See https://github.com/CommunityToolkit/dotnet/issues/881
614+
[TestMethod]
615+
public void Test_ObservableValidator_HasErrors_IncludeNonAutogenerateAttribute()
616+
{
617+
DerivedModelWithValidatableProperties model = new();
618+
619+
DisplayAttribute? displayAttribute = model.GetType().GetProperty(nameof(ObservableValidator.HasErrors))?.GetCustomAttribute<DisplayAttribute>();
620+
621+
Assert.IsNotNull(displayAttribute);
622+
Assert.IsFalse(displayAttribute.AutoGenerateField);
623+
}
611624

612625
public class Person : ObservableValidator
613626
{

0 commit comments

Comments
 (0)