简体   繁体   English

无法在Monotouch中正确使用通用版本的EventHandler

[英]Cannot Use Generic version of EventHandler in Monotouch properly

Here is the line of code...pretty simple and well-known for everyone... 这是代码行...非常简单,众所周知的每个人...

public event EventHandler<TimeSpan> TimeExtended;

in Visual Studio (on windows I mean) it works as usual but in MonoTouch I can't use TimeSpan because it is not convertible to EventArgs and I can only use the types who derives from EventArgs. 在Visual Studio中(我是说在Windows上),它可以照常工作,但在MonoTouch中,我不能使用TimeSpan,因为它不能转换为EventArgs,而我只能使用从EventArgs派生的类型。 How can I use that this generic event handler in mono? 如何在Mono中使用该通用事件处理程序?

Thanks 谢谢

It works in Visual Studio because you are using .Net 4.5 where the type constraint was dropped. 它在Visual Studio中有效,因为您使用的是放置了类型约束的.Net 4.5。 Just define your own class inheriting from EventArgs . 只需定义您自己的类即可继承EventArgs If you need additional data, then include it as well. 如果您需要其他数据,则也要包括它。

public class TimeExtendedEventArgs : EventArgs
{
  public TimeSpan TimeExtended { get; set; }
  public Player Player { get; set; }
}

public event EventHandler<TimeExtendedEventArgs> TimeExtended;

我做了这个事件处理程序,我想它正在工作。

public delegate void GEventHandler<T>(object sender, T args);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM