1

次のクラスがあります。

public class Item
{
}

public class ItemCollection<TItem> : ICollection<TItem> where TItem : Item, new()
{
}

私は2つの派生クラスを持っています:

public class Feature : Item
{
}

public class Features : ItemCollection<Feature>
{
}

このようなコレクションを管理するマネージャー クラスがあります。

public class ItemCollectionManager<TCollection> where TCollection : ItemCollection<Item>, new()
{
}

私はこのクラスを使用しようとしました:

public class FeatureManager : ItemCollectionManager<Features>
{
}

しかし、これは次の結果になります。

「型は、ジェネリック クラスで TCollection として使用するためにFeatures変換可能である必要があります」。ItemCollection<Item>ItemCollectionManager<TCollection>

そして前述の通り、

FeaturesですItemCollection<Feature>

FeatureですItem

インターフェイスがこのタスクの理想的な解決策であるとは思いませんが、理由が提供されれば喜んで変更します。

私が間違っていることについて誰かがアドバイスできれば、それは非常にありがたいです。

ありがとうございました。

4

2 に答える 2