【发布时间】:2009-10-27 09:05:33
【问题描述】:
我有这个功能:
程序 A
public ICollection<ReportLocationInfo> GetAllReportsInstalled()
{
return _Reports;
}
我通过反射动态调用它:
方案 B
internal ICollection<Object> Scan(string path)
{
MethodInfo GetReports =
_reportFactoryType.GetMethod("GetAllReportsInstalled");
return (List<Object>)GetReports.Invoke(_reportFactory, null);
}
我正在投射到列表,因为我在 Program B 没有ReportLocationInfo,而且我手头有自己的翻译功能。这当然行不通。
有什么建议吗?
【问题讨论】:
-
如果您无法访问程序 B 中的
ReportLocationInfo类,您将如何访问这些数据? -
Info.GetType().GetProperty("propertyName") 但我还有一个问题,如何访问列表中的每个 ReportInfo?
标签: c# generics reflection casting