Get concrete generic type by Enum
Hello. Can someone explain how I can solve my problem. I have interface IContainerService<T>
and Entity from Database with Type(Box, Pallet, BigBox etc.) and T(ProductCategory : Food, Animals, Clothes)
And here's problem when I get my Container from DB Idk how to get concrete type and execute AddProduct method
I've tried something like this but with no results cause IContainerBase doesn't contains AddProduct just general method.
How can I get concrete type based by information from Enums? I want to get like method CreateContainer but with concreteType where I can call AddProduct and GetProduct method
1 Reply
Your problem is pretty much that you want to weave together a mostly compile time concept with generics with a runtime evaluation of your container, so your best bet is either to
1) Cast to a IContainerService<T> at runtime
2) Move shared logic into the shared base interface
3) Find a different approach for your factory which can properly deal with returning a proper IContainerService<T>