CQRSalad.Tests.Dispatcher.UnitTest1.GetExecutor C# (CSharp) Метод

GetExecutor() приватный статический Метод

private static GetExecutor ( Type handlerType, Type messageType, MethodInfo action ) : HandlerExecutor
handlerType System.Type
messageType System.Type
action System.Reflection.MethodInfo
Результат HandlerExecutor
        private static HandlerExecutor GetExecutor(Type handlerType, Type messageType, MethodInfo action)
        {
            Type objectType = typeof (object);
            ParameterExpression handlerParameter = Expression.Parameter(objectType, "handler");
            ParameterExpression messageParameter = Expression.Parameter(objectType, "message");

            MethodCallExpression methodCall =
                Expression.Call(
                    Expression.Convert(handlerParameter, handlerType),
                    action,
                    Expression.Convert(messageParameter, messageType));

            if (action.ReturnType == typeof (void))
            {
                var lambda = Expression.Lambda<Action<object, object>>(
                    methodCall,
                    handlerParameter,
                    messageParameter);

                Action<object, object> voidExecutor = lambda.Compile();
                return (handler, message) =>
                {
                    voidExecutor(handler, message);
                    return null;
                };
            }
            else
            {
                var lambda = Expression.Lambda<HandlerExecutor>(
                    Expression.Convert(methodCall, typeof(object)),
                    handlerParameter,
                    messageParameter);

                return lambda.Compile();
            }
        }