Plugins: flexible & safe use of different assembly versions withdifferent features

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello.

Are there any resources out there (because I couldn´t find any)
concerning the usage of assemblies with different features in each version?

In other words:
I´ve got one assembly A that is using assembly B - B exists in different
versions. Now I want to make it possible for A to ask B what features it
supports or what data it can give to A.

Something like:

if (B.supports(detailedData))
useDetailedData();
else if (B.supports(lessDetailedData))
useLessDetailedData();
else
useData();

An older version of A may ask only the following:
if (B.supports(lessDetailedData))
useLessDetailedData();
else
useData();

I´ve tried something like this but it didn´t work for me!

Puh - hope I could make myself clear.
Thanks for any information!

Greetings,
Tim.
 
I'm not sure how you have created your assemblies, but generally
speaking, you would define an interface that B would implement. A
would be programmed against this interface. As long as the assembly
(B) has implemented the interface properly, it doesn't matter to A how
it is implemented, it should just work. This way, A doesn't have to
know what capabilities B has and B doesn't have to know what A
supplies. A just calls the interface, and B just implements it. I
suppose you could have A pass in its version number so that B can react
accordingly.

public interface IMyInterface
{
//interface definition here
public void InterfaceMethod();
}

public class PlugIn : IMyInterface
{
//PlugIn (B) implements the interface
public void InterfaceMethod()
{
//method implementation
}
}

public class Host
{
//Host class (A) uses the interface

IMyInterface var;

public Host()
{
var = getInterfaceInstance();
}

private IMyInterface getInterfaceInstance()
{
//code to instantiate an object that implements the interface
}

private void foo()
{
var.InterfaceMethod();
}
}

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top