The code below pretty much sums up what I want to achieve.
We have a solution which comprises many different projects however we have a need to be able to call methods in projects from projects which are not referenced (would cause circular reference).
I have posted previous questions and the code below is pretty much what I have come up with using interfaces. I still do not know how I can call a method that resides in a different project that is not referenced.
I cannot create an instance of the interface, it has to be a class. But how can I create an instance of a class that is not referenced. I do not want to use reflection for this.
Code is C# 2.0
Any help is appreciated.
What code do I need to place in "GeneralMethod" (Class Raise) to be able to execute the "Update" method in Class "Listen" ?
// Link Project
namespace Stack.Link
{
public class Interface
{
public interface Update
{
void Update();
}
}
}
// Project A
// References Link only
namespace Stack.ProjA
{
public class Raise
{
public void GeneralMethod()
{
// I want to place code in here to be able to execute
// "Update" method in ProjB.
// Keep in mind that ProjA and ProjB only reference
// Link Project
}
}
}
// Project B
// References Link only
namespace Stack.ProjB
{
public class Listen : Stack.Link.Interface.Update
{
public void Update()
{
// Do something here that is executed from ProjA
Console.Write("Executed Method in ProjB");
}
}
}
I should probably clarify the motivation behind needing to do this. Perhaps there is a better way ....
We have a baseform from which all other projects are referenced. As an example we pass an object which contains various settings to the project when it is loaded (from the baseform).
If for example, the settings object has some variables change (settings object populated in baseform), we would like the loaded project to listen for this change and obtain a new settings object.
Because the baseform references all the other projects, we need to have the projects "listen" for events in the baseform.
Clear as mud :-)