私は次のようにMethodInfoMakeGenericMethodを使用しようとしています。
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];
}
次の一般的な方法に対して:
public static bool TryConstruct<T>(string from, out IThingy result) where T : IThingy, new()
{
var thing = new T();
return thingTryConstructFrom(from, out result);
}
私が抱えている問題は、渡した型が'new()'ではないため、MakeGenericMethod行で引数の例外が発生することです。
これを回避する方法はありますか?ありがとう