I know there is some deep complex method for this in System.Reflections somewhere, but everywhere I have looked, it is just instantiating an object with a Type.
What I need is to define an object with a the object my type is, AND instantiate it.
I guess something like this.
(MyType.GetObject()) MyObject = Activator.Instantiate(MyType);
Where MyType is System.Type representing some class and MyObject is created to whatever type MyType represents.
I'm not sure what you mean, but if I understand you correctly, don't you mean [i]var[/i]?
var test = Activator.Instantiate(MyType);
?
You can only cast it if you know what the type is, and having a Type object isn't enough. Just pass the object around as an 'object' and cast it to whatever you need whenever you need it.
Dynamic typing is coming in C# 4.0 that will make this easier.
Sorry, you need to Log In to post a reply to this thread.