Hi,
I am trying to use the MethodInfo MakeGenericMethod as follows:
foreach (var type in types)
{
object output = null;
var method = typeof (ContentTypeResolver).GetMethod("TryConstruct");
var genmethod = method.MakeGenericMethod(type);
var arr = new object[] { from, output };
if ((bool)genmethod.Invoke(null, arr))
return (IThingy)arr[1];
}
Against the following generic method:
public static bool TryConstruct<T>(string from, out IThingy result) where T : IThingy, new()
{
var thing = new T();
return thingTryConstructFrom(from, out result);
}
The problem I having is that I get an arguement exception on the MakeGenericMethod line as the type I am passing is not 'new()'
Is there a way round this?? Thanks