> I'm sure I've seen this somewhere before, but can't find it 
> now. If I have the name of a type as a string (ie 
> "System.Text.StringBuilder," how do I use it to construct an 
> instance of that type?

        Let me be the first of many answering people ;)
-> 
1) load the assembly in an Assembly instance.
2) call CreateInstance(typenameString);

Example:
string entityAssemblyName = entityNode.Attributes["Assembly"].Value;
string entityTypeName = entityNode.Attributes["Type"].Value;
Assembly entityAssembly = Assembly.Load(entityAssemblyName);
EntityBase referencedEntity =
(EntityBase)entityAssembly.CreateInstance(entityTypeName);

OR you could use Activator.CreateInstance(), after creating a Type
object using Type.GetType(typenameString)

                Frans.

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

Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet

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

Reply via email to