我有隐式转换,用于返回 DomainResult
public static implicit operator DomainResult<TEntity>(TEntity resultData)
{
var result = new DomainResult<TEntity>
{
Result = resultData,
Succeeded = true
};
return result;
}
当我尝试通过IList
使用隐式转换时,它给了我编译时错误说明
Cannot implicitly convert type 'System.Collections.Generic.IList<string>' to
'...DomainResult<System.Collections.Generic.IEnumerable<string>>'.
An explicit conversion exists (are you missing a cast?)
。
IList<string> str = new PagedList<string>() { "example" };
DomainResult<IEnumerable<string>> dr = str; // I am getting compile time error
List<string> str = new PagedList<string>() { "example" };
DomainResult<IEnumerable<string>> dr = str; //this is valid
我该如何解决?