From d849b9af276da0aeadc42f3cb81f81ea64d8ebfe Mon Sep 17 00:00:00 2001 From: psyche <57017344+ddjerqq@users.noreply.github.com> Date: Thu, 23 Mar 2023 14:55:41 +0400 Subject: [PATCH 1/2] fix code formatting in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b129d69..bfb53a6 100644 --- a/README.md +++ b/README.md @@ -97,11 +97,11 @@ If you're using async validation, you can use the `ValidateAsync` method on the @code { private Person _person = new(); - private FluentValidationValidator? _fluentValidationValidator; + private FluentValidationValidator? _fluentValidationValidator; private void SubmitFormAsync() { - if (await _fluentValidationValidator!.ValidateAsync()) + if (await _fluentValidationValidator!.ValidateAsync()) { Console.WriteLine("Form Submitted Successfully!"); } From 26c7bb62477de7059f0687ff75c0d172d8e7c4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raffael=20Sch=C3=A4rer?= Date: Tue, 20 Feb 2024 16:28:25 +0100 Subject: [PATCH 2/2] Addresses an issue with collection expressions in C# 12 regarding IReadOnlyList --- .../EditContextFluentValidationExtensions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs b/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs index 24fba59..7ab8ab8 100644 --- a/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs +++ b/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs @@ -199,6 +199,16 @@ private static FieldIdentifier ToFieldIdentifier(in EditContext editContext, in var indexerValue = int.Parse(nextToken); newObj = array[indexerValue]; } + else if (obj is IReadOnlyList readOnlyList) + { + // Addresses an issue with collection expressions in C# 12 regarding IReadOnlyList: + // Generates a <>z__ReadOnlyArray which: + // - lacks an Item property, and + // - cannot be cast to object[] successfully. + // This workaround accesses elements directly using an indexer. + var indexerValue = int.Parse(nextToken); + newObj = readOnlyList[indexerValue]; + } else { throw new InvalidOperationException($"Could not find indexer on object of type {obj.GetType().FullName}.");