Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

get Type from string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ruben - 13 Nov 2006 17:06 GMT
Hi!

I am looking for an easy way to get a Type from a arbitrary string.
What I found looks like:

----
string TypeString = "System.String"; // only as example...
Type TypeIAmLookingFor = null;

Assembly[] appAssemblies =
System.AppDomain.CurrentDomain.GetAssemblies();

foreach (Assembly assembly in appAssemblies)
{
  foreach (Type type in assembly.GetTypes())
  {
     if (t.ToString().Equals(TypeString))
        TypeIAmLookingFor  = type;
  }
}
---

This is kind of overloaded; is there are more easy way to do this?

Thank you!
  Ruben
Carl Daniel [VC++ MVP] - 13 Nov 2006 17:16 GMT
> Hi!
>
[quoted text clipped - 19 lines]
>
> This is kind of overloaded; is there are more easy way to do this?

See System.Type.GetType(string typeName)

-cd
Ruben - 13 Nov 2006 17:54 GMT
Carl Daniel [VC++ MVP] schrieb:
> See System.Type.GetType(string typeName)

Thank you!

Sometimes it is hard to find the right place in the documentation... :-)
Jon Skeet [C# MVP] - 13 Nov 2006 19:23 GMT
> Carl Daniel [VC++ MVP] schrieb:
> > See System.Type.GetType(string typeName)
>
> Thank you!
>
> Sometimes it is hard to find the right place in the documentation... :-)

Note, however, that Type.GetType with just the "plain" type name (i.e.
without full assembly information) will only search in mscorlib and the
currently executing assembly. If you need to look in other assemblies,
either call GetType on the appropriate Assembly reference, or specify
the assembly details in the argument to Type.GetType.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.