Type.GetType( stringType );

Jeff Block


-----Original Message-----
From: Bill Bassler [mailto:[EMAIL PROTECTED]
Sent: Monday, April 05, 2004 11:36 AM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Using reflection internally to create an instance
based on a string name

Can reflection be used internally to create a class instance based on an
input string containing the class name? Something somewhat similar to the
code below however typeof takes a type as an argument, not a string.

Activator.CreateInstance seems to require that a reference to the containing
.dll is obtained. I'm interested in creating an instance of a class defined
in the same assembly as the creator method based on an input string that
matches the class name.

// Some dll
public abstract class InstanceCreator
{
   public static InstanceCreator GetObject(string type)
   {
 return typeof(type); // return type with name corresponding to input string
   }
}

public class SomeClass1
{
}

public class SomeClass2
{
}

// end some dll

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com Some .NET
courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com


**********************************************************************
PLEASE NOTE: The above email address has recently changed from a previous naming 
standard -- if this does not match your records, please update them to use this new 
name in future email addressed to this individual.

This message and any attachments are intended for the
individual or entity named above. If you are not the intended
recipient, please do not forward, copy, print, use or disclose this
communication to others; also please notify the sender by
replying to this message, and then delete it from your system.

The Timken Company
**********************************************************************

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to