473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

get Type from string

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

Nov 13 '06 #1
3 21199
"Ruben" <Mr****@gmx.dewrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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?
See System.Type.GetType(string typeName)

-cd
Nov 13 '06 #2
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... :-)

Nov 13 '06 #3
Ruben <Mr****@gmx.dewrote:
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.

--
Jon Skeet - <sk***@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
Nov 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: chobin | last post by:
Hi all. I've a terrible question. I've to build one XML page (based on a xml schema) that implements a dynamic database. In particular, I would declare something like this: <?xml version="1.0"...
3
by: dgaucher | last post by:
Hi, I want to consume a Web Service that returns a choice, but my C++ client always receives the same returned type. On the other hand, when I am using a Java client, it is working fine (of...
2
by: Jason Cartwright | last post by:
I have an abstract base class and two derived classes that I want to serialize and deserialize with schema validation. When I serialize instances of the derived classes the XmlSerializer adds the...
3
by: Mike in Paradise | last post by:
I have an application that is being passed objects which could either be an instance or a Type in the case of a Static Class When you do the GetType on the object that was originally a Static...
3
by: Imran Aziz | last post by:
Hello All, I am getting the following error on our production server, and I dont get the same error on the development box. Unable to cast object of type 'System.Byte' to type 'System.String'. ...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
0
by: Chris Fink | last post by:
When I am consuming a webservice, an object has an undefined value (inq3Type.Call3Data). I do not completely understand why this is happening and apologize for the vague question. My assumption...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
42
by: blisspikle | last post by:
I tried closely copying some code that I found on this group for assigning a type at runtime, but I cannot get it to work. Can someone see what is wrong with my logic? Thanks, Private Sub...
5
by: mknoll217 | last post by:
I am a newbie at XML. I have been given an xml document that I need to write the schema for, for a class assignment. The xml given to me is <?xml version="1.0"?> <Vendors> <Vendor> ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.