泛型方法中的Where子句

本文关键字:子句 Where 泛型方法 | 更新日期: 2023-09-27 17:57:47

我有一个泛型方法,它接受两个泛型参数:BType和IType。有没有办法在方法签名中定义BType必须是IType的实现?!?

第1版:这里的方法签名:

public static Expression<Func<BType, bool>> CastFunc<BType,IType>(Expression<Func<IType, bool>> customWhereClause)

泛型方法中的Where子句

public void Foo<BType, IType>(BType a, IType b) where BType : IType
public static Expression<Func<BType, bool>> CastFunc<BType,IType>(Expression<Func<IType, bool>> customWhereClause) where BType : IType

文档"类型参数的限制":http://msdn.microsoft.com/en-us/library/d5x73970.aspx