public class Account
{
}
public class SpecificationBase<T>
{
}
public class AccountSearch : SpecificationBase<Account>
{
}
public class SearchBase<T> where T : SpecificationBase<T>
{
}
public class Start
{
public Start()
{
new SearchBase<AccountSearch>();
}
}
错误:类型“
的隐式引用转换AccountSearch
”不能在通用类型或方法“T
”中用作类型参数“SearchBase<T>
”。没有从“AccountSearch
”到“SpecificationBase<AccountSearch>
”
答案 0 :(得分:1)
虽然其他答案事实上是正确的并且会使问题消失,但我认为您正在寻找的是以下内容:
public class Account
{
}
public class SpecificationBase<T>
{
}
public class AccountSearch : SpecificationBase<Account>
{
}
public class SearchBase<T, TModel> where T : SpecificationBase<TModel>
{
}
public class Start
{
public Start()
{
new SearchBase<AccountSearch, Account>();
}
}
答案 1 :(得分:0)
错误是自我解释的。将限制更改为具体类型以执行有效转换:
public class Account
{
}
public class SpecificationBase<T>
{
}
public class AccountSearch : SpecificationBase<Account>
{
}
public class SearchBase<T> where T : SpecificationBase<Account>
{
}
public class Start
{
public Start()
{
new SearchBase<AccountSearch>();
}
}
}