rlrcstr

I have a scenario where I want to read the name of a type from an xml file and then either instantiate an object of that type or (depending on the situation) pass the type of the type...

Pseudocode:

bool CreateOneOfThese(string typeName)

{

declare object of type typeName;

instantiate an object of type typeName;

//Or perhaps

convert object x to type of (typeName);

}

Do I need reflection to do this sine the type is coming in as a string

Thanks.

J




Re: Visual C# General Do I need reflection?


Re: Visual C# General Do I need reflection?

boban.s

You don't need Reflection. Just read the file but how to use the info from file, is different story and we nead real example not pseudo one.




Re: Visual C# General Do I need reflection?

rlrcstr

I ended up using Type.GetType("TypeName") using a fully qualified assembly reference. And it works perfectly.

So the answer is that I don't need reflection, I just needed to dig a bit deeper in the documentation.

Thanks for the responses guys.

J