Reputation: 17498
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";
}
}
Upvotes: 1
Views: 403
Reputation: 17498
Problem has been solved.
I had no idea delegates can be declared at the namespace level without being in a class.
Upvotes: 3
Reputation: 1166
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)
Upvotes: 3
Reputation: 2023
IMyProgram is declaring a scope of public for the delegate and the events. Remove them, and I think you will be able to compile
Upvotes: 1