diff --git a/README.md b/README.md index 02b1e46..2a95284 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ If you're using async validation, you can use the `ValidateAsync` method on the private async void SubmitFormAsync() { - if (await _fluentValidationValidator!.ValidateAsync()) + if (await _fluentValidationValidator!.ValidateAsync()) { Console.WriteLine("Form Submitted Successfully!"); } diff --git a/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs b/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs index f9855ce..f879a7a 100644 --- a/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs +++ b/src/Blazored.FluentValidation/EditContextFluentValidationExtensions.cs @@ -227,6 +227,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}.");