Can a string be used to declare a type in C#?
Instead of:
MyType foo = bar;
You would have a string of "MyType".
string typeString = "MyType";
TypeOftypeString foo = bar;
Obviously I don't know the correct way to do this. So the above example is just a way to convey what I am thinking.
In Unity3D, I can set a string to be a specific value before runtime. Can I use that string to define a type? Even if this ends up being an illogical pursuit in my code, is this possible? If so, how do you go about it?
Edit: To Expand on what I said. MyType is a class within the application. I also have MyOtherType and MyDifferantType. I want to be able to have that string be "MyType" or "MyOtherType" and then assign an already created instance of that object to that field. I'm trying to avoid a really long if-else chain or switch() statement where I make a case for each type that the object may encounter, even if that type is pre-determined when the string is set before runtime.
If this seems like a fools errand, let me know.