Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Question about referencing a control at runtime
Message
De
02/03/2004 00:42:25
 
 
À
02/03/2004 00:34:28
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00881833
Message ID:
00882246
Vues:
32
Hey Kevin,

Yes, you can use a string. I'm sorry, I probably should have just pasted some code in here for you originally, but I thought you might like to look it up yourself! <g>

This is kinda the way we do it:
string DLLName = "MyDLL";
string ClassName = "MyClass";
System.Reflection.Assembly oDLL;
object oClass;

// This "loads" the .DLL
oDLL = System.Reflection.Assembly.LoadFrom(DLLName);

// This creates the class instance
oClass = oDLL.CreateInstance(ClassName);
Does that answer your question?

~~Bonnie



>Hi, Bonnie...
>
>Follow-up question...in a nutshell, I was able to do what I needed by the following, using a simple interface to identify the custom container that I need to drop on a form at runtime:
>
>System.Reflection.Assembly oDLL;
>UserControl oControl = new UserControl();
>oDLL = System.Reflection.Assembly.LoadFrom("MyExternal.DLL");
>foreach(Type o in oDLL.GetTypes())
> if(o is ICustomContainer) // simple interface
>
> oControl = (UserControl)Activator.CreateInstance(o);
>
>This works...but what I'm curious about is whether I can call CreateInstance, passing instead a string for the name of the container that I want to drop on the form.
>
>The online helps says that CreateInstance can receive a string, but I keep running into problems with the object that it returns. I need to look at this further, but was curious if you had a quick answer.
>
>It may be better if I just stick with using a simple interface anyway, but was just curious (maybe for down the road) if I can call createinstance with a string.
>
>Thanks!
>Kevin
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform