Exemple #1
0
        /// <summary>
        /// Creates a static delegate from an Action, allowing the action's target to be provided at a later time.
        /// </summary>
        /// <param name="methodInfo">The method to create an OpenAction from.</param>
        /// <returns>An OpenAction not ties to any specific target.</returns>
        /// <exception cref="ArgumentException"><paramref name="methodInfo"/> is referencing a static method.</exception>
        public static Action <object, TParam1, TParam2> CreateOpenAction <TParam1, TParam2>(MethodInfo methodInfo)
        {
            if (methodInfo.IsStatic)
            {
                throw new ArgumentException("Cannot create open action from static method", "methodInfo");
            }

            IOpenActionFactory factory = CreateOpenActionFactory(methodInfo.DeclaringType);

            return(factory.CreateOpenAction <TParam1, TParam2>(methodInfo));
        }
Exemple #2
0
        private static IOpenActionFactory CreateOpenActionFactory(Type targetType)
        {
            lock (typeof(OpenAction))
            {
                if (_lastFactoryTargetType != targetType)
                {
                    Type openActionFactoryType = typeof(OpenActionFactory <>).MakeGenericType(targetType);
                    _lastFactory           = (IOpenActionFactory)Activator.CreateInstance(openActionFactoryType);
                    _lastFactoryTargetType = targetType;
                }

                return(_lastFactory);
            }
        }