Skip to content

Commit cd5cc40

Browse files
committed
Fixed nullability warning in ObservableValidator
Also fixed some build warnings in the unit test project
1 parent ebdef69 commit cd5cc40

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Microsoft.Toolkit.Mvvm/ComponentModel/ObservableValidator.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,13 @@ static Action<object> GetValidationAction(Type type)
489489
static Action<object> GetValidationActionFallback(Type type)
490490
{
491491
// Get the collection of all properties to validate
492-
PropertyInfo[] validatableProperties = (
492+
(string Name, MethodInfo GetMethod)[] validatableProperties = (
493493
from property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
494494
where property.GetIndexParameters().Length == 0 &&
495-
property.GetCustomAttributes<ValidationAttribute>(true).Any() &&
496-
property.GetMethod is not null
497-
select property).ToArray();
495+
property.GetCustomAttributes<ValidationAttribute>(true).Any()
496+
let getMethod = property.GetMethod
497+
where getMethod is not null
498+
select (property.Name, getMethod)).ToArray();
498499

499500
// Short path if there are no properties to validate
500501
if (validatableProperties.Length == 0)

UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using Microsoft.Toolkit.Mvvm.ComponentModel;
1313
using Microsoft.VisualStudio.TestTools.UnitTesting;
1414

15-
#pragma warning disable SA1124
15+
#pragma warning disable SA1124, SA1307, SA1401
1616

1717
#nullable enable
1818

@@ -371,7 +371,7 @@ public partial class ModelWithValuePropertyWithValidation : ObservableValidator
371371
[MinLength(5)]
372372
private string? value;
373373
}
374-
374+
375375
public partial class ViewModelWithValidatableGeneratedProperties : ObservableValidator
376376
{
377377
[Required]

0 commit comments

Comments
 (0)