public static object ConvertFunc(Func <object, Task> func, Type type) { if (func == null) { return(null); } var fp = new FuncProxy(func); var makeGenericType = typeof(Func <,>).MakeGenericType(type, typeof(Task)); // ReSharper disable once PossibleNullReferenceException var methodInfo = typeof(FuncProxy).GetMethod("InvokeAsync").MakeGenericMethod(type); var @delegate = Delegate.CreateDelegate(makeGenericType, fp, methodInfo); return(@delegate); }
public static object?ConvertFunc(Func <object?, Task>?func, Type?type) { if (func == null) { return(null); } if (type == null) { throw new ArgumentNullException(nameof(type)); } var fp = new FuncProxy(func); var makeGenericType = typeof(Func <,>).MakeGenericType(type, typeof(Task)); var methodInfo = typeof(FuncProxy).GetMethod("InvokeAsync") !.MakeGenericMethod(type); var @delegate = Delegate.CreateDelegate(makeGenericType, fp, methodInfo); return(@delegate); }