首先,我想说我对C#sharp很新。有没有办法实现如下构造?或者还有其他方法可以存档吗?
public interface IClass
{
Dictionary<Enum, ISecondClass> { get; }
}
public abstract class ClassBase : IClass
{
public abstract Dictionary<Enum, ISecondClass> { get; protected set;}
}
public class ConcreteClass : ClassBase
{
public override Dictionary<ConreteEnum, ISecondClass> { get; protected set;}
}
编辑: 我忘了说Dictionary的具体实例需要实现一个自定义的Enum-comparer,需要一个具体的枚举来初始化
对于所有对自定义枚举比较器感兴趣的人,请查看此链接:Custom-Enum-Comparer
答案 0 :(得分:4)
您可以在类/接口级别添加泛型类型参数
public interface IClass<TEnum>
{
Dictionary<TEnum, ISecondClass> { get; }
}
public abstract class ClassBase<TEnum> : IClass<TEnum>
{
public abstract Dictionary<TEnum, ISecondClass> { get; protected set;}
}
public class ConcreteClass : ClassBase<ConcreteEnum>
{
public override Dictionary<ConcreteEnum, ISecondClass> { get; protected set;}
}