c# - c# 使用接口(IList)进行隐式转换
问题描述
我有返回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
我怎样才能解决这个问题?
解决方案
推荐阅读
- node.js - 使用 mongoose 保存到 mongodb 失败但未显示错误
- r - R CMD 检查:全局变量没有可见绑定(使用包中的数据/数据集时)
- terraform - 使用 Terraform 创建 vsphere_virtual_machine 资源后展开 Linux 分区
- react-navigation - react-navigation - react native 中堆栈导航内的抽屉导航
- python - Feedparser 只返回数字而不是整个 URL
- r - 将公共列值交换到 R 中特定行的同一列
- python-3.x - pip install theanets 失败错误
- memory-leaks - 使用具有大型中间体的函数使用 dask 建立内存
- amazon-web-services - AWS - 从另一个 VPC 中的 AMI 构建时,SSH 到 EC2 超时
- laravel - Composer 在安装新的 laravel 库时遇到问题