Fixed nullability warning in ObservableValidator

Also fixed some build warnings in the unit test project
This commit is contained in:
Sergio Pedri
2021-09-28 14:39:46 +02:00
parent 181e63f9a2
commit 755eb70bdc
2 changed files with 7 additions and 6 deletions
@@ -489,12 +489,13 @@ namespace Microsoft.Toolkit.Mvvm.ComponentModel
static Action<object> 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<ValidationAttribute>(true).Any() &&
property.GetMethod is not null
select property).ToArray();
property.GetCustomAttributes<ValidationAttribute>(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)
@@ -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]