Exemplo n.º 1
0
 private static ReduceWithoutActionParameterHandler CreateStaticReducerWithoutActionParameter(
     DiscoveredReducerMethod discoveredReducerMethod)
 =>
 (ReduceWithoutActionParameterHandler)
 Delegate.CreateDelegate(
     type: typeof(ReduceWithoutActionParameterHandler),
     method: discoveredReducerMethod.MethodInfo);
Exemplo n.º 2
0
 private static ReduceWithoutActionParameterHandler CreateReducerWithoutActionParameter(
     object reducerHostInstance,
     DiscoveredReducerMethod discoveredReducerMethod)
 =>
 reducerHostInstance == null
                         ? CreateStaticReducerWithoutActionParameter(discoveredReducerMethod)
                         : CreateInstanceReducerWithoutActionParameter(reducerHostInstance, discoveredReducerMethod);
Exemplo n.º 3
0
 public ReducerWrapper(object reducerHostInstance, DiscoveredReducerMethod discoveredReducerMethod)
 {
     Reduce =
         discoveredReducerMethod.RequiresActionParameterInMethod
                         ? CreateReducerWithActionParameter(reducerHostInstance, discoveredReducerMethod)
                         : WrapReducerWithoutActionParameter(reducerHostInstance, discoveredReducerMethod);
 }
Exemplo n.º 4
0
 private static ReduceWithoutActionParameterHandler CreateInstanceReducerWithoutActionParameter(
     object reducerHostInstance,
     DiscoveredReducerMethod discoveredReducerMethod)
 =>
 (ReduceWithoutActionParameterHandler)
 Delegate.CreateDelegate(
     type: typeof(ReduceWithoutActionParameterHandler),
     firstArgument: reducerHostInstance,
     method: discoveredReducerMethod.MethodInfo);
Exemplo n.º 5
0
        private static ReduceWithActionParameterHandler WrapReducerWithoutActionParameter(
            object reducerHostInstance,
            DiscoveredReducerMethod discoveredReducerMethod)
        {
            ReduceWithoutActionParameterHandler handler = CreateReducerWithoutActionParameter(
                reducerHostInstance,
                discoveredReducerMethod);

            return(new ReduceWithActionParameterHandler((state, action) => handler.Invoke(state)));
        }
Exemplo n.º 6
0
        internal static object Create(IServiceProvider serviceProvider, DiscoveredReducerMethod discoveredReducerMethod)
        {
            Type stateType  = discoveredReducerMethod.StateType;
            Type actionType = discoveredReducerMethod.ActionType;

            Type   hostClassType       = discoveredReducerMethod.HostClassType;
            object reducerHostInstance = discoveredReducerMethod.MethodInfo.IsStatic
                                ? null
                                : serviceProvider.GetService(hostClassType);

            Type classGenericType = typeof(ReducerWrapper <,>).MakeGenericType(stateType, actionType);
            var  result           = Activator.CreateInstance(
                classGenericType,
                reducerHostInstance,
                discoveredReducerMethod);

            return(result);
        }