Esempio n. 1
0
        public Func <object, object[], TReturn> GetMethodInvoker <TReturn>(
            MethodInfo methodInfo,
            DelegateCreationMode creationMode)
        {
            var dictionary = nonVoidMethodGenericDictionary;

            if (!dictionary.TryGetValue(methodInfo, out object result))
            {
                switch (creationMode)
                {
                case DelegateCreationMode.SlowCreationFastPerformance:
                    result = ReflectionCompiler.CreateMethodFunc <TReturn>(methodInfo);
                    break;

                default:
                    result = new Func <object, object[], TReturn>(
                        (owner, args) => (TReturn)methodInfo.Invoke(owner, args));
                    break;
                }

                dictionary[methodInfo] = result;
            }

            return((Func <object, object[], TReturn>)result);
        }
Esempio n. 2
0
        public Func <object, object[], object> GetMethodInvoker(
            MethodInfo methodInfo)
        {
            Func <object, object[], object> func;

            var lockSlim   = nonVoidMethodLockSlim;
            var dictionary = nonVoidMethodDictionary;

            lockSlim.EnterUpgradeableReadLock();
            try
            {
                if (!dictionary.TryGetValue(methodInfo, out func))
                {
                    lockSlim.EnterWriteLock();
                    try
                    {
                        if (!dictionary.TryGetValue(methodInfo, out func))
                        {
                            func = ReflectionCompiler.CreateMethodFunc(methodInfo);
                            dictionary[methodInfo] = func;
                        }
                    }
                    finally
                    {
                        lockSlim.ExitWriteLock();
                    }
                }
            }
            finally
            {
                lockSlim.ExitUpgradeableReadLock();
            }

            return(func);
        }
Esempio n. 3
0
        public Func <object, object[], TReturn> GetMethodInvoker <TReturn>(
            MethodInfo methodInfo)
        {
            object func;

            var lockSlim   = nonVoidMethodGenericLockSlim;
            var dictionary = nonVoidMethodGenericDictionary;

            lockSlim.EnterUpgradeableReadLock();
            try
            {
                if (!dictionary.TryGetValue(methodInfo, out func))
                {
                    lockSlim.EnterWriteLock();
                    try
                    {
                        if (!dictionary.TryGetValue(methodInfo, out func))
                        {
                            var result = ReflectionCompiler.CreateMethodFunc <TReturn>(methodInfo);
                            dictionary[methodInfo] = result;
                            return(result);
                        }
                    }
                    finally
                    {
                        lockSlim.ExitWriteLock();
                    }
                }
            }
            finally
            {
                lockSlim.ExitUpgradeableReadLock();
            }

            return((Func <object, object[], TReturn>)func);
        }
Esempio n. 4
0
        public Func <object, object[], object> GetMethodInvoker(
            MethodInfo methodInfo,
            DelegateCreationMode creationMode)
        {
            var dictionary = nonVoidMethodDictionary;

            if (!dictionary.TryGetValue(methodInfo, out var result))
            {
                switch (creationMode)
                {
                case DelegateCreationMode.SlowCreationFastPerformance:
                    result = ReflectionCompiler.CreateMethodFunc(methodInfo);
                    break;

                default:
                    result = methodInfo.Invoke;
                    break;
                }

                dictionary[methodInfo] = result;
            }

            return(result);
        }