diff --git a/Microsoft.Toolkit.Mvvm/ComponentModel/ObservableValidator.cs b/Microsoft.Toolkit.Mvvm/ComponentModel/ObservableValidator.cs index 3af5b171..9ed34818 100644 --- a/Microsoft.Toolkit.Mvvm/ComponentModel/ObservableValidator.cs +++ b/Microsoft.Toolkit.Mvvm/ComponentModel/ObservableValidator.cs @@ -489,12 +489,13 @@ namespace Microsoft.Toolkit.Mvvm.ComponentModel static Action GetValidationActionFallback(Type type) { // Get the collection of all properties to validate - PropertyInfo[] validatableProperties = ( + (string Name, MethodInfo GetMethod)[] validatableProperties = ( from property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public) where property.GetIndexParameters().Length == 0 && - property.GetCustomAttributes(true).Any() && - property.GetMethod is not null - select property).ToArray(); + property.GetCustomAttributes(true).Any() + let getMethod = property.GetMethod + where getMethod is not null + select (property.Name, getMethod)).ToArray(); // Short path if there are no properties to validate if (validatableProperties.Length == 0) diff --git a/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs b/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs index 82610c81..c51dee59 100644 --- a/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs +++ b/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs @@ -12,7 +12,7 @@ using System.Reflection; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.VisualStudio.TestTools.UnitTesting; -#pragma warning disable SA1124 +#pragma warning disable SA1124, SA1307, SA1401 #nullable enable @@ -371,7 +371,7 @@ namespace UnitTests.Mvvm [MinLength(5)] private string? value; } - + public partial class ViewModelWithValidatableGeneratedProperties : ObservableValidator { [Required]