tradeline
asked on
Reflection Help
I'd like to dynamically return a type of object at runtime. It is late-bound, based on a variable set inside the class.
For example:
Vendor v = ObjectDB.getInstance(int id);
ObjectDb has a method getInstance() which determines it's return value at runtime, based on a variable "returnValue" inside of itself. In this case, returnValue is set to "Vendor" because I want to return an instance of the Vendor class.
Can someone show me an example/best practice of how to achieve this?
Thanks.
For example:
Vendor v = ObjectDB.getInstance(int id);
ObjectDb has a method getInstance() which determines it's return value at runtime, based on a variable "returnValue" inside of itself. In this case, returnValue is set to "Vendor" because I want to return an instance of the Vendor class.
Can someone show me an example/best practice of how to achieve this?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
object obj = new ObjectDB; // assuming you have a way to get to this object in C#