public abstract class FillWorkBook<TModel, Chart> where TModel : struct where Chart : new() where Chart : CreateExcelBase { public void FillDataToWorkbook(Workbook workbook) { List<TModel> sheetData = GetData(); if (sheetData == null) { sheetData = new List<TModel>(); } DataTable dt = AsConvert.ListToDataTable(sheetData); CreateExcelBase chart = new Chart(); chart.FillData = dt; chart.CreateCharts(workbook); } public abstract List<TModel> GetData(); }
执行上述代码编译报错:
错误 3 已经为类型参数“Chart”指定了 constraint 子句。必须在单个 where 子句中指定类型参数的所有约束。 D:\SourceProject\OLAP\trunk\EntOlap\EntOlap.Report\EntOlap.Report.Service\KefuDuizhangBiao\FillWorkBook.cs 15 11 EntOlap.Report.Service
类的方法声明改为如下即可:
public abstract class FillWorkBook<TModel, Chart> where TModel : struct where Chart : CreateExcelBase,new()
时间: 2024-10-04 17:28:20