mirror of
https://github.com/CommunityToolkit/dotnet.git
synced 2026-10-20 14:16:34 +08:00
Fixed nullability warning in ObservableValidator
Also fixed some build warnings in the unit test project
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user