tags:

views:

2190

answers:

2

I have a problem: imagine I have a plugin-based system.

I need some kind of interface with which I could catch events from every plugin, which implements for example IReporting interface.

(IReporting) object.OnSomeEvent += <.....>

But I can't find a way to do that.

+8  A: 

Instead of (IReporting)obj.XXX you should write ((IReporting)obj).XXX

public interface IFoo
{
    event EventHandler Boo;
}

class Foo : IFoo
{
    public event EventHandler Boo;
    public void RaiseBoo()
    {
        if (Boo != null)
            Boo(this, EventArgs.Empty);
    }
}

...

private void TestClass_Boo(object sender, EventArgs e)
{
    throw new NotImplementedException();
}

    ...

   object o = new Foo();
   ((IFoo)o).Boo += TestClass_Boo;
   ((Foo)o).RaiseBoo();

Regarding plugin framework take a look at existing solutions with good architecture, for example MEF

aku
A: 

And how can I pass some kind of Message or smth ?

Lukas Šalkauskas
do you understand that provided information is not sufficient to recommend any solution? provide detailed use cases of your plugin system
aku
f.ex: Work() method, should fire event OnWorkStarted(DateTime.Now) or smth like that.
Lukas Šalkauskas
so, what is the problem with Work method? why can't it raise some event? describe full use case - how plugin is registered, etc.
aku
I solved that :) thanks for Your help ^^
Lukas Šalkauskas