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?
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.
If i undestood answers under your question than maybe you are looking for something like this (instantiate Type):
Assembly asmApp = Assembly.LoadFile("some.dll"); Type tApp = asmApp.GetType("Namespace.SomeClass"); object oApp = Activator.CreateInstance(tApp, new object[0] { });
I'll base my answer on the clarification you provided in a comment:
I misunderstood what everyone said here or at least I did not make myself clear. I want to get the class as I would use it normally. For example, I have to pass the class like this:
public void methodName<T>()
whereT
is the class.
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:
Use the "Activator" class:
Activator.CreateInstance<T>
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