Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with IReadOnlyList<> and C# 12 Syntax #215

Open
Schaeri opened this issue Feb 20, 2024 · 1 comment
Open

Incompatibility with IReadOnlyList<> and C# 12 Syntax #215

Schaeri opened this issue Feb 20, 2024 · 1 comment
Labels
Bug Something isn't working Triage Issue needs to be triaged

Comments

@Schaeri
Copy link

Schaeri commented Feb 20, 2024

We have identified an issue with Blazored/FluentValidation following the migration to .NET 8.0 and C# 12. Since we work with Fluxor, all our data is immutable. Moreover, we use the IReadOnlyList<> interface for lists throughout.

With the new C# 12 syntax for list initialization, a "standard" list/array is no longer created; instead, a type named "<>z__ReadOnlyArray" is generated. This new type neither possesses an Item property nor can it be converted into an object array. The code in the ToFieldIdentifier method within the EditContextFluentValidationExtensions class throws an exception as a result.

The following example demonstrates the problem (Note: the code must be compiled with C# 12, and we have tested with Visual Studio 17.9.0):

List<string> list = ["1", "2"];
IReadOnlyList<string> readonlyList = ["1", "2"];

var listHasItemProperty = list.GetType().GetProperties().Any(x => x.Name == "Item");
var readOnlyListHasItemProperty = readonlyList.GetType().GetProperties().Any(x => x.Name == "Item");

Console.WriteLine(listHasItemProperty); // True
Console.WriteLine(readOnlyListHasItemProperty); // False

var objects = readonlyList as object[];
Console.WriteLine(objects != null); // False

The following PR resolves the issue #214

@Schaeri Schaeri added Bug Something isn't working Triage Issue needs to be triaged labels Feb 20, 2024
@Schaeri
Copy link
Author

Schaeri commented Mar 19, 2024

Thank you very much for accepting the pull request. When will the package be released on NuGet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant