我有方法readExcelFile(),它采用参数和泛型类型,其中泛型类型是类,所以想法是给这个方法require参数来读取excel文件,我得到具有excel记录的对象列表。我如何定义界面中的IList <T>
的所有工作正常,这种状态之上,但我还需要定义接口
public interface IProcessExcel
{
IList<T> ReadExcelFile(string filePath, int readExcelRowFrom, int headerRow);
}
,并在上面的代码中,我得到错误
The Type or namespace T could not be found(missing directive or assembly)
实现代码
public class ProcessExcel<T>: IProcessExcel where T: class
{
private static Excel.Application xlApp;
private static Excel.Workbook xlWorkbook;
private static Excel.Worksheet xlWorkSheet;
private static Excel.Range xlRange;
private string GivenFilePath = string.Empty;
private IList<string> ExcelFileExtensionList = new string[] { ".xls", ".xlsx", ".xlsm", ".xltx", ".xltm" };
private T newObject;
List<T> ExcelRecordList = new List<T>();
public ProcessExcel()
{
}
public IList<T> ReadExcelFile(string filePath, int readExcelRowFrom, int headerRow)
{
this.FilePath = filePath;
this.ReadExcelRowFrom = readExcelRowFrom;
this.HeaderRow = headerRow;
this.ReferenceClass = typeof(T);
this.ValidateExcelFile();
this.ProcessReadExcelFile();
return ReadExcelFile;
}
这意味着它会改变实现类中的实现! – toxic
不,它没有。它会让你在实例化时定义'T'。 –