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

Provide virtual ElementType property at the TypeReference level #841

Open
Zastai opened this issue Feb 26, 2022 · 0 comments
Open

Provide virtual ElementType property at the TypeReference level #841

Zastai opened this issue Feb 26, 2022 · 0 comments

Comments

@Zastai
Copy link
Contributor

Zastai commented Feb 26, 2022

TypeReference has properties like IsArray to be able to know what specific type it is without needing a cast.

It also has a GetElementType() method. However, somewhat counter-intuitively, that returns the innermost element type, so for ref decimal[] it returns System.Decimal, and for Func<int, bool>[] it returns System.Func`2 (not a generic instance, losing the int and bool entirely).

So in order not to break the API, could a virtual ElementType property be added at the TypeReference level (with the one on TypeSpecification becoming an override)? That would avoid having to use casts all over the place.

Alternatively, maybe add an overload of GetElementType() taking a boolean "innermost" flag, with the existing no-argument version calling through to that, passing true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant