【发布时间】:2012-08-18 00:52:31
【问题描述】:
我在尝试引发对象的事件时遇到问题,该对象的类型实现了另一个类的接口(事件所在的位置)。
这是我的代码:
界面 IBaseForm
public interface IBaseForm
{
event EventHandler AfterValidation;
}
实现IBaseForm接口的Form
public partial class ContactForm : IBaseForm
{
//Code ...
public event EventHandler AfterValidation;
}
我的控制器:发生错误的地方
错误信息:
AfterValidation 事件只能出现在左侧 += 或 -=(在 IBaseForm 类型中使用时除外)
public class MyController
{
public IBaseForm CurrentForm { get; set; }
protected void Validation()
{
//Code ....
//Here where the error occurs
if(CurrentForm.AfterValidation != null)
CurrentForm.AfterValidation(this, new EventArgs());
}
}
提前致谢
【问题讨论】: