I am attempting to use generics so I can dynamically pass various different model lists to Excel sheets for export. I was hoping to use the class below to make my final list of models to export.
public class ExcelExport<T>
{
public List<T> ExportList { get; set; }
public string SheetName { get; set; }
}
This is one of my many failed attempted usages: Cannot convert List(object) to List<ExcelExport>
//Export Declaration
public async Task<byte[]> ExportToExcelAsync<T>(List<ExcelExport<T>> excelExports)
//Attempted calls
var export = new List<object>();
var list1 = getTypeList1Data();
export.Add(new ExcelExport<TypeList1>() { ExportList = list1, SheetName = "Sheet1" });
var list2 = getTypeList2Data();
export.Add(new ExcelExport<TypeList2>() { ExportList = list2, SheetName = "Sheet2" });
var result = await _excelFunctions.ExportToExcelAsync<object>(export);
Hoping some more versed in generics than myself might have a solution?