【发布时间】:2020-07-16 08:45:27
【问题描述】:
有一个类似这样的通用接口
interface IMatch<T>
{
bool MatchWithExpected(T actualValue);
}
这个接口针对不同类型的实现已经可用(Int、struct、Enum 等)。
我有一个名为ObjectType 的结构。我想要一个与ObjectType 列表一起使用的上述接口的实现。
我能够做到这一点的唯一方法是执行以下操作
class MultiStructMatch<T> : IMatch<T> where T is List<ObjectType>
有什么方法可以使List<ObjectType> 泛型表示List<struct>?
我尝试了List<System.ValueType>,但无法将List<ObjectType> 转换为List<System.ValueType>。
【问题讨论】:
-
看来你真正想要的是
class MultiStructMatch<T>:IMatch<List<T>> where T:struct