Is there a good way to use a object from Type Type in a generic method?
I have a lot of serialized different Objects in a Database along with their typename as string. All of them share the same Interface. Now i want to deserialize all of those to the right Objects.
Therefore i created a Application scanner that collects the Types for all those objects. Now i want to compare the typenames and deserialize them in a loop.
All of this feels wrong.
sth. like this
7 Replies
the storedObject contains the typename as string and the actual object as string
There is a non generic overload that takes the Type object as a method parameter. If you can have a mapping of strings to the actual type objects (like a dictionary or even just a switch expression) you can use that maybe?
Generics need to be known at compile time
Not if you're willing to write very gnarly reflection code ![when](https://cdn.discordapp.com/emojis/968512924698169415.png)
![when](https://cdn.discordapp.com/emojis/968512924698169415.png)
Shhh
But yes generally don't do that
Thx.