.NET AddIn Development
I am writing a program that allows developers to write AddIn for it, and I would like the developers to be able to hook up to events that occur in the program.
My code won't compile because I can't declare a delegate in the IMyProgram interface.
So, I suppose it's more of a design issue. How could you get the interface passed to AddIn so that AddIn can connect to 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
source to share
3 answers
If you want to implement an eventing model for your Addins, you should use delegates instead of interfaces - check this one from MSDN to see if it cleans up anything:
When to Use Delegates Instead of Interfaces (C # Programming Guide)
+3
source to share