Esempio n. 1
0
        public static WeakFunc <T1, T2, T3, T4, TResult> Create <T1, T2, T3, T4, TResult>(Func <T1, T2, T3, T4, TResult> func)
        {
            var weakDelegate = new WeakDelegate(func.Target, func.Method);

            return((arg1, arg2, arg3, arg4) =>
            {
                if (weakDelegate.TryInvoke(new object[] { arg1, arg2, arg3, arg4 }, out var result))
                {
                    return (true, (TResult)result);
                }
                return (false, default(TResult));
            });
        }
Esempio n. 2
0
        public static WeakFunc <TResult> Create <TResult>(Func <TResult> func)
        {
            var weakDelegate = new WeakDelegate(func.Target, func.Method);

            return(() =>
            {
                if (weakDelegate.TryInvoke(null, out var result))
                {
                    return (true, (TResult)result);
                }
                return (false, default(TResult));
            });
        }