我正在尝试在 C# 中进行一些智能事件处理,但我遇到了一条错误消息:
无法将类型“System.EventHandler”隐式转换为 xxxxCompletedEventHandler
我有一段看起来像这样的代码:
_ServiceAgentArt.Test((s,e) => _List = e.ListOfDTOArt, new DTOArt { Gruppe_id = 1700 });
在 ServiceAgentArt 类的 Test 方法中,我有以下代码:
public delegate void getArterCompletedEventHandler(getArterCompletedEventArgs e);
public class getArterCompletedEventArgs : EventArgs
{
public List<DTOArt> ListOfDTOArt { get; set; }
}
sealed class ServiceAgentArt : ServiceAgentBase
{
public event getArterCompletedEventHandler EventGetArterCompleted;
public void Test(EventHandler<getArterCompletedEventArgs> e, DTOArt _DTOArt)
{
EventGetArterCompleted += e;
this.GetFromWEBAPI(string.Format("/apiart/getarter?id={0}", _DTOArt.Gruppe_id));
}
protected override void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (EventGetArterCompleted != null)
EventGetArterCompleted(new getArterCompletedEventArgs { ListOfDTOArt = e.Result.DecodeJSONFromStream<List<DTOArt>>() });
}
}
但是.Net 不喜欢代码行EventGetArterCompleted += e; ,我完全理解它试图告诉我的内容,不能将 eventargs 强制转换为 eventhandler。
我肯定在这里遗漏了一些东西,有没有办法将事件处理程序 e 添加到委托 EventGetArterCompleted ????
提前致谢,周末愉快:-)
托马斯,哥本哈根,丹麦