我有以下代码:
if (FileType == typeof(ScanUploadFile))
{
files.Add(new ScanUploadFile(filePath));
}
if (FileType == typeof(FaxFile))
{
files.Add(new FaxFile(filePath));
}
if (FileType == typeof(BulkScanFile))
{
files.Add(new BulkScanFile(filePath));
}
if (FileType == typeof(SpecialCategoryFile))
{
files.Add(new SpecialCategoryFile(filePath));
}
Run Code Online (Sandbox Code Playgroud)
如果没有IF声明我怎么写呢?
由于您只对构造函数感兴趣,因此您可以使用:
Activator.CreateInstance(FileType, new string[] {filePath});
Run Code Online (Sandbox Code Playgroud)
Activator在System库中定义.