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

            return(new ReduceWithActionParameterHandler((state, action) => handler.Invoke(state)));
        }
Example #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);
        }