假设:
public delegate void MyHandler(object sender, EventArgs<SomeArgs> e)
public interface MyInterface
{
event MyHandler TheEvent;
}
class MyClass:MyInterface
{
public event MyHandler TheEvent;
}
class TheProblemClass:FrameworkElement //, IPossibleInterface?
{
public MyClass Instance1{get;set;}
public MyClass Instance2{get;set;}
//You used an instance of MyClass, now you must handle Instance1.TheEvent
//You used another instance of MyClass, now you must handle must handle Instance2.TheEvent
//...for any instance of MyClass, MUST handle TheEvent
}
好的,所以我打算让其他开发人员使用MyClass
的实例创建自己的类。有什么方法可以强制声明MyClass
实例的范围来处理事件吗?