I get the Type but that's not the same as the Class which is what I'm looking for.
Is there an inverse operation of typeof?
EDIT
I need the class in order to use a generic repository:
GenericRepository<BaseEntity> repository = new GenericRepository<BaseEntity>(new AzureBrightData());
I started by writing BaseEntity from which all entity class descend, but the problem is that the repository needs to know which table to search for.
For example, if we have a partition key and row key combination pair of (1,1) this doesn't allow me or the repository to know from which table to get the registry. It's not enough and that's why I believe I need the table.
I think you are looking for Activator.CreateInstance.
I must be missing something. The answers provided so far don't seem to match the questions. I would love more clarity.
Nevertheless I'll try to answer the question as I see it.
You say you're trying to do this:
Are you trying to do something more like this?
If so, then your generic repository class needs to be defined as such:
Then you can define your
BaseEntity
class as you have been, but the instantiation of your repository will give you the actual class - and I hope then the table - that you are looking for.I hope I have understood your question.
Here are a few options listed in order of my preference. I am assuming that
T
is the type parameter in your generic class or method.or
or
or
If i undestood answers under your question than maybe you are looking for something like this (instantiate Type):
Use the "Activator" class:
I'll base my answer on the clarification you provided in a comment:
Short answer: No, you can't, because generic types are resolved at compile time.
Long answer: Yes, you can, but you need to use reflection. Here's how you do that: