From 755eb70bdc2eb9febebb2c98645b5067fbc4e8cc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 28 Sep 2021 14:39:46 +0200 Subject: [PATCH] Fixed nullability warning in ObservableValidator Also fixed some build warnings in the unit test project --- .../ComponentModel/ObservableValidator.cs | 9 +++++---- .../Mvvm/Test_ObservablePropertyAttribute.cs | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) 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]