Dear Customer,
You can consider my code as somewhat Design Pattern issue although it seems that did not follow any pattern exactly. >Where does the MyEventClass come in and why exactly?
The class is not necessary, because we declare an interface, MyEventInterface, so we must have code to implement the interface and fire the event. We can do all of what the MyEventClass does in the Plugin. But if we want create another Plugin class that follow the interface, we have to do the code in the MyEventClass again.
>as to the host/main application - I cannot seem to see the method being implemented to fire the event. I implement the code that fire event in the class below. public class MyEventClass : MyEventInterface { public event DoSomething EventDoSomething; public void FireEvent(string text) { if (null != EventDoSomething) EventDoSomething(text); } }
>Why do we create the MyEventClass? How will this be implemented in A plugin? >"void FireEvent(string text) { if (null != EventDoSomething) EventDoSomething(text); }" >this is in the MyEventClass, how would this be implemented in A plugin? Or would the developer have to do this, just as we do when we are raising events >>from our application?
See comment 1, this is not necessary. We have implement the event in MyEventClass and our plugin inherit from the class, we do not do that again.
If you have experience in Win32, this event modal is just a callback mechanism, when we subscribe the event, we are put the function point of the event handler func into the event class. When we fire the event, we are trying to call the function point.
oPlugin.FireEvent("Fire event")
oPlugin is a reference to the plugin class which implement the interface MyEventInterface. So the call above, will finall call the method FireEvent which will call the event handler function.
public class MyEventClass : MyEventInterface { public event DoSomething EventDoSomething; public void FireEvent(string text) { if (null != EventDoSomething) EventDoSomething(text); // this is how .NET event modal works in C#. } }
If you have confusion with event modal, please refer to the link below. Events (C# Programming Guide) http://msdn2.microsoft.com/en-us/library/awbftdfh.aspx
If you still have any concern, please feel free to post here.
Best regards, Peter Huang
This posting is provided "AS IS" with no warranties, and confers no rights. |