I need to use a common interface, for example:
public interface IContainer<T>
{
IEnumerable<IContent<T>> Contents { get; }
}
An object that implements this interface is returned using a common method, such as:
IContainer<T> GetContainer<T>(IProperty property);
Type Tunknown before execution.
Using reflection, I can call the method GetContainer<T>and get the result.
My problem is that I don’t know how to list the result with the type Object(therefore, I cannot attribute it to IEnumerable).
I also tried casting as follows, but it doesn’t work (it says “Type expected”):
var myContainer = genericMethodInfo.Invoke(
myService,
new object[] { property })
as typeof(IContainer<>).MakeGenericType(type);
where typeis the runtime type, myServiceis the service that provides the method GetContainer<T>, and propertyhas the type IPropertyas needed.
UPDATE: . : http://stefanoricciardi.com/2010/02/18/generics-with-type-uknown-at-compile-time/