[3.0/LINQ] Get Type object from string
I'm reading a string from a file, which would be something like "char", or "bool" etc. I'm trying to get a type object from it. While working out how to do this i've tried the code below, but it doesn't work.
Any ideas why?
Code:
Type T = Assembly.GetAssembly(typeof(char)).GetType("System.char", true);
Type T = Assembly.GetAssembly(typeof(char)).GetType("char", true);
Thanks for any help.
Re: [3.0/LINQ] Get Type object from string
This works fine for me:
CSharp Code:
Assembly asm = Assembly.GetAssembly(typeof(char));
Type typ = asm.GetType("System.Char");
That said, it's useless for you because you're using the actual type to get the assembly in the first place, but you don't know the actual type at design time because you're not reading the type name until run time.
Re: [3.0/LINQ] Get Type object from string
Thanks for the reply. I've got it working now, not sure why my testing example didn't work.
What i was trying was just an example while i was figuring out relevent classes etc. then i encountered the error and thought i was doing something fundamentally wrong. I realise i can't do typeof(char) since i dont' know what 'char' will be.
Thanks again. :)