A simple way would be:
private ICollection<object> ScanInternal(string path)
{
List<object> result = new List<object>();
MethodInfo GetReports =
_reportFactoryType.GetMethod("GetAllReportsInstalled");
IEnumerable reports = GetReports.Invoke(_reportFactory, null)
as IEnumerable;
if (reports != null) // or exception if null ?
{
foreach (object report in reports)
result.Add(report);
}
return result;
}
But a more appropriate way would be to create an interface in a separate shared assembly (e.g. IReportLocationInfo), and then use this interface in both assemblies.
Consider refactoring your code a bit to achieve this, because invoking methods using Reflection on an object instance is almost like doing plain C. You get no type safety.
So, the OOP way would be to have all interfaces in a separate assembly (referenced by both program A and program B):
public interface IReportFactory
{
IEnumerable<IReportLocationInfo> GetAllReportsInstalled();
}
public interface IReportLocationInfo
{
void SomeMethod();
}
And then implement your concrete factories inside "plug-in" assemblies (program A):
public class MyReportFactory : IReportFactory
{
// ...
}
And then cast each plugin to a IReportFactory after loading inside program B.