コード例 #1
0
ファイル: FuncHelper.cs プロジェクト: mingyaaaa/NetRpc
        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);
        }
コード例 #2
0
ファイル: FuncHelper.cs プロジェクト: ErgEnn/NetRpc
        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);
        }