tags:

views:

192

answers:

3

Hi,

I'm writing a program that allows developers to write AddIn's for it and I'd like developers to be able to hook into events happening in the program.

My code isn't compiling because I can't declare a delegate in the IMyProgram interface.

So I suppose this is more of a design question. How would you go about getting an interface passed to the AddIn so the AddIn can hook into program events?

[AddInContract]
    public interface IMyProgramAddInContract : IContract {

        /// <summary>
        /// Initializes AddIn
        /// </summary>
        void Init(IMyProgram instance);

        System.Drawing.Image AddInIcon { get; }

        String DisplayName { get; }

        String Description { get; }
    }

    [AddInContract]
    public interface IMyProgram : IContract {

        public delegate EventHandler EmailEventHandler(object sender, EmailEventArgs args);

        public event EmailEventHandler BeforeCheck;
        public event EmailEventHandler AfterCheck;
        public event EmailEventHandler EmailDownloaded;
        public event EmailEventHandler OnProcessMessage;

    }

    [AddInBase]
    public class EmailEventArgs : EventArgs {

        public override string ToString() {
            return "todo";
        }
    }
+1  A: 

IMyProgram is declaring a scope of public for the delegate and the events. Remove them, and I think you will be able to compile

Gutzofter
Didn't work. Interfaces cannot declare types :(
Sir Psycho
+2  A: 

If you're looking to implement an eventing model for your Addins, then you should use delegates instead of interfaces - check out this blurb from MSDN to see if it clears anything up:

When to Use Delegates Instead of Interfaces (C# Programming Guide)

Gunny
+3  A: 

Problem has been solved.

I had no idea delegates can be declared at the namespace level without being in a class.

Sir Psycho