Hi,
I have some code to load some plug-ins, but the code requires me to know
the name of the class to load (here: SamplePlugin, derived from IPlugin) :
(Here is some C# code, but I use VB.Net to code my program)
using System;
using System.Reflection;
public class Driver
{
static void Main()
{
Assembly assembly = Assembly.LoadFrom ("myplugin.dll");
Type t = assembly.GetType ("SamplePlugin");
IPlugin plugin = (IPlugin) Activator.CreateInstance(t);
plugin.SayHello();
}
}
The problem is, I don't want to have to know the name of the class I want to
load... I want to load the new module and get an instance of the class that
derives IPlugin. Is there a way to do so?
In C++ for the same purpose, I had a win32 dll with an extern function that
returned an instance of the contained class, so I loaded the dll, called the
function and I was ready to proceed. Is there something similar I can do
with .NET class libraries?
thanks 5 1436
ThunderMusic wrote: I have some code to load some plug-ins, but the code requires me to know the name of the class to load (here: SamplePlugin, derived from IPlugin) :
Assembly assembly = Assembly.LoadFrom ("myplugin.dll"); Type t = assembly.GetType ("SamplePlugin");
The problem is, I don't want to have to know the name of the class I want to load... I want to load the new module and get an instance of the class that derives IPlugin. Is there a way to do so?
foreach (Type Exported in assembly.GetExportedTypes())
if (Exported.IsClass && Exported.GetInterface("IPlugin", true) !=
null)
;
-- www.midnightbeach.com
Hello,
I have 'played around' with using plugins and came across the same
issue. One way around is to create an attribute that can only be used one
and only in a '[assembly:xxxx]' level. The attribute constructor can take a
string for description and a string or a type for another. Then when you
load that assembly just look for your assembly-based attribute and you will
have an indication of the class that you can instantiate. Also, in the
construct of your attribute you could check that the type you pass it is
compatible with your IPlugin interface.
Hope this helps, If you have any problems then drop me a line!
Alan Seunarayan
"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:41***************@midnightbeach.com... ThunderMusic wrote:
I have some code to load some plug-ins, but the code requires me to know the name of the class to load (here: SamplePlugin, derived from IPlugin) :
Assembly assembly = Assembly.LoadFrom ("myplugin.dll"); Type t = assembly.GetType ("SamplePlugin");
The problem is, I don't want to have to know the name of the class I want to load... I want to load the new module and get an instance of the class that derives IPlugin. Is there a way to do so?
foreach (Type Exported in assembly.GetExportedTypes()) if (Exported.IsClass && Exported.GetInterface("IPlugin", true) != null) ; --
www.midnightbeach.com
Hello,
I have 'played around' with using plugins and came across the same
issue. One way around is to create an attribute that can only be used one
and only in a '[assembly:xxxx]' level. The attribute constructor can take a
string for description and a string or a type for another. Then when you
load that assembly just look for your assembly-based attribute and you will
have an indication of the class that you can instantiate. Also, in the
construct of your attribute you could check that the type you pass it is
compatible with your IPlugin interface.
Hope this helps, If you have any problems then drop me a line!
Alan Seunarayan
"Jon Shemitz" <jo*@midnightbeach.com> wrote in message
news:41***************@midnightbeach.com... ThunderMusic wrote:
I have some code to load some plug-ins, but the code requires me to know the name of the class to load (here: SamplePlugin, derived from IPlugin) : Assembly assembly = Assembly.LoadFrom ("myplugin.dll"); Type t = assembly.GetType ("SamplePlugin");
The problem is, I don't want to have to know the name of the class I want to load... I want to load the new module and get an instance of the class that derives IPlugin. Is there a way to do so?
foreach (Type Exported in assembly.GetExportedTypes()) if (Exported.IsClass && Exported.GetInterface("IPlugin", true) != null) ; --
www.midnightbeach.com
"ThunderMusic" <NO*******@sympatico.caSPAMATALL> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl... Hi, I have some code to load some plug-ins, but the code requires me to know the name of the class to load (here: SamplePlugin, derived from IPlugin) :
(Here is some C# code, but I use VB.Net to code my program) using System; using System.Reflection;
public class Driver { static void Main() { Assembly assembly = Assembly.LoadFrom ("myplugin.dll"); Type t = assembly.GetType ("SamplePlugin"); IPlugin plugin = (IPlugin) Activator.CreateInstance(t); plugin.SayHello(); } }
The problem is, I don't want to have to know the name of the class I want to load... I want to load the new module and get an instance of the class that derives IPlugin. Is there a way to do so?
In C++ for the same purpose, I had a win32 dll with an extern function that returned an instance of the contained class, so I loaded the dll, called the function and I was ready to proceed. Is there something similar I can do with .NET class libraries?
thanks
You could also just drop plugins in your plugin directory, get the public
class names and pick those that supports your interface...
Patrice
--
"Alan Seunarayan" <so****@ntlw0rld.c0m> a écrit dans le message de
news:EC*****************@newsfe3-gui.ntli.net... Hello, I have 'played around' with using plugins and came across the same issue. One way around is to create an attribute that can only be used one and only in a '[assembly:xxxx]' level. The attribute constructor can take
a string for description and a string or a type for another. Then when you load that assembly just look for your assembly-based attribute and you
will have an indication of the class that you can instantiate. Also, in the construct of your attribute you could check that the type you pass it is compatible with your IPlugin interface.
Hope this helps, If you have any problems then drop me a line!
Alan Seunarayan
"Jon Shemitz" <jo*@midnightbeach.com> wrote in message news:41***************@midnightbeach.com... ThunderMusic wrote:
I have some code to load some plug-ins, but the code requires me to know the name of the class to load (here: SamplePlugin, derived from
IPlugin) :
Assembly assembly = Assembly.LoadFrom ("myplugin.dll"); Type t = assembly.GetType ("SamplePlugin");
The problem is, I don't want to have to know the name of the class I
want to load... I want to load the new module and get an instance of the class that derives IPlugin. Is there a way to do so?
foreach (Type Exported in assembly.GetExportedTypes()) if (Exported.IsClass && Exported.GetInterface("IPlugin", true) != null) ; --
www.midnightbeach.com "ThunderMusic" <NO*******@sympatico.caSPAMATALL> wrote in message news:ue**************@TK2MSFTNGP12.phx.gbl... Hi, I have some code to load some plug-ins, but the code requires me to know the name of the class to load (here: SamplePlugin, derived from IPlugin)
: (Here is some C# code, but I use VB.Net to code my program) using System; using System.Reflection;
public class Driver { static void Main() { Assembly assembly = Assembly.LoadFrom ("myplugin.dll"); Type t = assembly.GetType ("SamplePlugin"); IPlugin plugin = (IPlugin) Activator.CreateInstance(t); plugin.SayHello(); } }
The problem is, I don't want to have to know the name of the class I
want to load... I want to load the new module and get an instance of the class that derives IPlugin. Is there a way to do so?
In C++ for the same purpose, I had a win32 dll with an extern function that returned an instance of the contained class, so I loaded the dll, called the function and I was ready to proceed. Is there something similar I can
do with .NET class libraries?
thanks
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JD Kronicz |
last post by:
Hi .. I have an issue I have been beating my head against
the wall on for some time. I am trying to use late
binding for MS graph so that my end users don't have to
worry about having the right...
|
by: Composer |
last post by:
I've read many postings about the problem of Access.References.IsBroken
and the consensus seems to be that late binding is the cure-all.
I have a very complex Access application that needs...
|
by: Zlatko Matić |
last post by:
I was reading about late binding, but I'm not completely sure what is to be
done in order to adjust code to late binding...
For example, I'm not sure if this is correct:
early binding:
Dim ws...
|
by: ThunderMusic |
last post by:
Hi,
I have some code to load some plug-ins, but the code requires me to know
the name of the class to load (here: SamplePlugin, derived from IPlugin) :
(Here is some C# code, but I use VB.Net to...
|
by: eBob.com |
last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been
wanting this capability for a long time. But it seems that I cannot
use it with Option Strict On. In an event handler I have ......
|
by: lgbjr |
last post by:
hi All,
I've decided to use Options Strict ON in one of my apps and now I'm trying
to fix a late binding issue. I have 5 integer arrays:
dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
|
by: Tim Roberts |
last post by:
I've been doing COM a long time, but I've just come across a behavior
with late binding that surprises me. VB and VBS are not my normal
milieux, so I'm hoping someone can point me to a document...
|
by: ADezii |
last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile...
|
by: Siv |
last post by:
hi,
I am converting an application that writes to an Excel spreadsheet and the
code trips the "option Strict" that I would like on because the parser says
"option Strict On disallows late...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |