【发布时间】:2020-01-06 23:16:03
【问题描述】:
我一直在努力解决这个问题,并查看了类似的问题,但在这里没有得到正确的解决方案。
我正在使用通用类来保存导出配置
public class SpreadsheetConfiguration<T> where T : class
{
public IEnumerable<T> ExportData {get; set;}
// More stuff here
}
我有一种情况,我需要这些列表,可能不是同一类型,例如这样
public byte[] ExportMultipleSheets(IEnumerable<SpreadsheetConfiguration<object>> toExport)
但我一辈子都无法弄清楚如何完成这项工作,我已经查看了上面关于制作 ISpreadsehetConfiguration 或其他方式的其他路线。
这是一个开源项目:https://github.com/IowaComputerGurus/netcore.utilities.spreadsheet
我知道我遗漏了一些东西,但我已经尝试了以上所有方法,但仍然没有达到我仍然可以做的最终用法
var toExport = new SpreadsheetConfiguration<MyOtherClass>();
因为转换失败
【问题讨论】:
标签: c# .net generics covariance