By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

getting list of classes interfaces

P: n/a
Hi!

Here's my problem:
Let's say I have 2 interfaces:
interface Module1
{
public void method1();
}

interface Module2
{
public void method2();
}

I'm using late binding, so at compile-time I don't know which modules I'll
be loading as I want
to provide a simple plug-in functionality.
So now I load my class from assembly.dll. How do I know which interfaces has
my class
implemented? Module1, Module2 or perhaps both or even none.

As mentioned before I would like to provide a simple plugin functionality,
similar to the one VS.NET has.
So if someone writes a plugin for my application he would implement the
IModule interface.
If the users module would like to add something to the menubar, he would
implement
IModuleMenu as well.

Is this a good way of doing this?

thanks,
saso

Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Here you have a sample code. The idea is to use Reflection to discover type
information at runtime:

public interface IModuleOne
{
string GetInfo ();
}

public interface IModuleTwo
{
string GetData ();
}

public class TestClass : IModuleOne, IModuleTwo
{
public string GetInfo ()
{
return "Info";
}

public string GetData ()
{
return "Data";
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
try
{
Type[] myObjectArray= typeof(TestClass).GetInterfaces();
Console.WriteLine("The Interfaces inherited by the MyTemplate class are
:\n");
for (int index = 0; index < myObjectArray.Length; index++)
{
Console.WriteLine(myObjectArray[index].FullName + ", " +
myObjectArray[index].Name);
}
}
catch (Exception e)
{
Console.WriteLine("Exception Raised !");
Console.WriteLine("Message : " + e.Message);
}
Console.ReadLine ();
}
}

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply

"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:bv**********@planja.arnes.si...
Hi!

Here's my problem:
Let's say I have 2 interfaces:
interface Module1
{
public void method1();
}

interface Module2
{
public void method2();
}

I'm using late binding, so at compile-time I don't know which modules I'll
be loading as I want
to provide a simple plug-in functionality.
So now I load my class from assembly.dll. How do I know which interfaces has my class
implemented? Module1, Module2 or perhaps both or even none.

As mentioned before I would like to provide a simple plugin functionality,
similar to the one VS.NET has.
So if someone writes a plugin for my application he would implement the
IModule interface.
If the users module would like to add something to the menubar, he would
implement
IModuleMenu as well.

Is this a good way of doing this?

thanks,
saso


Nov 15 '05 #2

P: n/a
thanks... that help a lot! :)

"Cezary Nolewajka" <c.*********************@no-sp-am-eh-mail.com> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
Here you have a sample code. The idea is to use Reflection to discover type information at runtime:

public interface IModuleOne
{
string GetInfo ();
}

public interface IModuleTwo
{
string GetData ();
}

public class TestClass : IModuleOne, IModuleTwo
{
public string GetInfo ()
{
return "Info";
}

public string GetData ()
{
return "Data";
}
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
try
{
Type[] myObjectArray= typeof(TestClass).GetInterfaces();
Console.WriteLine("The Interfaces inherited by the MyTemplate class are :\n");
for (int index = 0; index < myObjectArray.Length; index++)
{
Console.WriteLine(myObjectArray[index].FullName + ", " +
myObjectArray[index].Name);
}
}
catch (Exception e)
{
Console.WriteLine("Exception Raised !");
Console.WriteLine("Message : " + e.Message);
}
Console.ReadLine ();
}
}

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply

"Saso Zagoranski" <sa*************@guest.arnes.si> wrote in message
news:bv**********@planja.arnes.si...
Hi!

Here's my problem:
Let's say I have 2 interfaces:
interface Module1
{
public void method1();
}

interface Module2
{
public void method2();
}

I'm using late binding, so at compile-time I don't know which modules I'll be loading as I want
to provide a simple plug-in functionality.
So now I load my class from assembly.dll. How do I know which interfaces

has
my class
implemented? Module1, Module2 or perhaps both or even none.

As mentioned before I would like to provide a simple plugin functionality, similar to the one VS.NET has.
So if someone writes a plugin for my application he would implement the
IModule interface.
If the users module would like to add something to the menubar, he would
implement
IModuleMenu as well.

Is this a good way of doing this?

thanks,
saso

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.