Here's a simple class: public sealed class ClassLoader { public static object CreateClass(string assemblyName, string className) { Assembly assembly=System.Reflection.Assembly.LoadWithPartialName(assemblyName); Type type=assembly.GetType(className,true,true); if (assembly!=null) return Activator.CreateInstance(type); else return null; } }
Use it: Object obj=ClassLoader.CreateClass("Your.Assembly.Name","Your.NameSpace.ClassNa me"); > -----Original Message----- > From: Moderated discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED] On Behalf Of Shell > Sent: Monday, March 17, 2003 2:23 PM > To: [EMAIL PROTECTED] > Subject: [ADVANCED-DOTNET] Scripting Engine > > > Hi Everyone, > > I need a sub that creates an instance of an object whose > class name is passed in. > > Sub CreateInstance(ByVal className as String) > Dim obj As New "className"() ' "className" is whatever class > name passed in End Sub > > I tried to use the Script Control as follows. but it throwed > a System.Runtime.InteropServices.COMException > > Sub CreateInstance(ByVal className as String) > Dim sc As MSScriptControl.ScriptControl > sc = New MSScriptControl.ScriptControlClass() > sc.Language = "VBScript" > Dim command as String = "Dim obj As New " & className & "()" > sc.ExecuteStatement(command) > End Sub > > If you know what's going on, or you have other ideas to do > this (VB or C#), please help me. Thanks so much, Shell [EMAIL PROTECTED] > > =================================== > This list is hosted by DevelopMentorR http://www.develop.com > You may be interested in Guerrilla .NET, 24 March 2003, in > London and Boston http://www.develop.com/courses/gdotnet > > View archives and manage your subscription(s) at http://discuss.develop.com - - =================================== This list is hosted by DevelopMentorŪ http://www.develop.com You may be interested in Guerrilla .NET, 24 March 2003, in London and Boston http://www.develop.com/courses/gdotnet View archives and manage your subscription(s) at http://discuss.develop.com