public interface IAutomatizableEvent
{
Event AutomatizableEventItem { get; }
bool CanBeAutomatic { get; }
bool IsAutomaticallyRunning { get; }
bool OnBeforeAutomaticCall();
bool OnAutomaticCheck();
void OnAutomaticStart();
void OnAutomaticCancel();
}
public abstract class AutomatizableEvent : IAutomatizableEvent
{
public AutomatizableEvent()
{
}
#region Implementation of IAutomatizableEvent
public abstract Event AutomatizableEventItem { get; }
public abstract bool CanBeAutomatic { get; }
public abstract bool IsAutomaticallyRunning { get; }
public abstract bool OnBeforeAutomaticCall();
public abstract bool OnAutomaticCheck();
public abstract void OnAutomaticStart();
public abstract void OnAutomaticCancel();
#endregion
}
public static class EventSystem
{
public static List<EventSystemBase<Event, AutomatizableEvent>> AutomatizableEvents { get; set; }
[...]
}
“‘AutomatizableEvent’类型必须有一个公共(public)无参数构造函数,以便将其用作泛型类‘EventSystemBase’中的参数‘K’”
public abstract class EventSystemBase<T, K> : AutomatizableEvent
where T : Event
where K : AutomatizableEvent, new()
我的问题是...... AutomatizableEvent DO HAVE 没有公共(public)无参数构造函数吗??
最佳答案
错误描述错误,但错误正确。
AutomatizableEvent
不能用作通用参数 K
因为约束 where K : new()
.抽象类不满足该约束。
抽象类的构造函数始终受到有效保护,因为抽象只能作为派生类的基子对象创建,构造函数同样只能由派生类的构造函数调用,并且只能在构造函数链中。特别是它不能被 EventSystemBase<T, K>
使用在上下文中 new K()
.
关于c# - 必须有一个公共(public)的无参数构造函数,不是吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5657248/