473,472 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

getting list of classes interfaces

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
2 1382
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robert Zurer | last post by:
I notice that Microsoft puts their interfaces and classes in the same assembly. For example System.Data contains OleDbConnection and IDbConnection etc. I have found it useful to keep my...
9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
30
by: Frank Rizzo | last post by:
We are having one of those religious debates at work: Interfaces vs Classes. My take is that Classes give you more flexibility. You can enforce a contract on the descendant classes by marking...
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
0
by: submicron | last post by:
Hi All, I'm having problems implementing a readonly interface to a set of classes. Heres a simplification of the code: interface IreadonlyBase { // Does gets only on base class } class...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
1
by: shapper | last post by:
Hello, On my MVC projects I often create classes which contains properties which are lists of other classes. Should I start using IQueryable<Tor IEnumerable<Tinstead of List<T>? What are...
4
by: Peter | last post by:
Hi I was wondering about the use of interfaces for "data classes". Actually I don't know the accepted term for these types of classes - they are simply classes which have getters and setters, to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.