So I'm currently working on porting a project from Java to C#, and I'm trying to figure something out.
Currently, in Java, when we query something of the generic type, it erases the Generic type. And because of that, when we query something, we need to use Annotation so that we can get a collection and know what we get.
In C#, is this the same issue? Can C# generics be queried at run time? If we do, do we need to use the attributes to solve the issue?
Can C# generics be queried at run time?
Yes. The generic types are not erased in C#, as they are part of the type information itself. You should not need to add attributes to your objects in C# for this purpose.
That being said, by using generic methods in addition to your generic types, you may not need to "query" the type, as you can construct the appropriate type up front.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With