为什么这会给编译器带来错误?EventAggregator Helper通用方法
public class EventAggregationHelper {
public static SubscriptionToken SubscribeToEvent<T>(IEventAggregator eventAggregator) where T : EventBase {
T evt = eventAggregator.GetEvent<T>();
//T evt = eventAggregator.GetEvent<T>();
return null;
}
}
的错误是:
严重性代码说明项目文件的线路抑制状态 错误CS0310“T”必须是为了用它作为参数的非抽象类型具有公共的无参数的构造函数在通用类型或方法 'TEventType' 'IEventAggregator.GetEvent()' EntitySetGridTWPF d:\ DEVELOPER.NET \ COMERCIAL \ EntityBookCommon \ EntitySetGridTWPF \ EventAggregation \ EventAggregationHelper.cs 9主动
就行了:
T evt = eventAggregator.GetEvent<T>();
我以前用过这种方法调用其他泛型方法并且工作过。 GetEvent有什么特别之处?
在此先感谢。
也许从阅读和理解错误的提示开始。 – kiziu
@kiziu相信我,当我告诉你我在尝试搜索信息并尝试太多事情之前,在任何论坛上发问,包括这个。有时候每个人都有愚蠢的错误。 –