|
-
Jul 15th, 2008, 02:31 AM
#1
Thread Starter
Not NoteMe
[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.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jul 15th, 2008, 06:33 AM
#2
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.
-
Jul 15th, 2008, 07:16 AM
#3
Thread Starter
Not NoteMe
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.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|