Beispiel #1
0
 private static HandleWithoutActionParameterAsyncHandler CreateStaticHandlerWithoutActionParameter(
     DiscoveredEffectMethod discoveredEffectMethod)
 =>
 (HandleWithoutActionParameterAsyncHandler)
 Delegate.CreateDelegate(
     type: typeof(HandleWithoutActionParameterAsyncHandler),
     method: discoveredEffectMethod.MethodInfo);
Beispiel #2
0
 private static HandleWithoutActionParameterAsyncHandler CreateHandlerWithoutActionParameter(
     object effectHostInstance,
     DiscoveredEffectMethod discoveredEffectMethod)
 =>
 effectHostInstance == null
                         ? CreateStaticHandlerWithoutActionParameter(discoveredEffectMethod)
                         : CreateInstanceHandlerWithoutActionParameter(effectHostInstance, discoveredEffectMethod);
Beispiel #3
0
 public EffectWrapper(object effectHostInstance, DiscoveredEffectMethod discoveredEffectMethod)
 {
     HandleAsync =
         discoveredEffectMethod.RequiresActionParameterInMethod
                         ? CreateHandlerWithActionParameter(effectHostInstance, discoveredEffectMethod)
                         : WrapEffectWithoutActionParameter(effectHostInstance, discoveredEffectMethod);;
 }
Beispiel #4
0
 private static HandleWithoutActionParameterAsyncHandler CreateInstanceHandlerWithoutActionParameter(
     object effectHostInstance,
     DiscoveredEffectMethod discoveredEffectMethod)
 =>
 (HandleWithoutActionParameterAsyncHandler)
 Delegate.CreateDelegate(
     type: typeof(HandleWithoutActionParameterAsyncHandler),
     firstArgument: effectHostInstance,
     method: discoveredEffectMethod.MethodInfo);
Beispiel #5
0
        private static HandleWithActionParameterAsyncHandler WrapEffectWithoutActionParameter(
            object effectHostInstance,
            DiscoveredEffectMethod discoveredEffectMethod)
        {
            HandleWithoutActionParameterAsyncHandler handler = CreateHandlerWithoutActionParameter(
                effectHostInstance,
                discoveredEffectMethod);

            return(new HandleWithActionParameterAsyncHandler((action, dispatcher) => handler.Invoke(dispatcher)));
        }
Beispiel #6
0
        internal static IEffect Create(IServiceProvider serviceProvider, DiscoveredEffectMethod discoveredEffectMethod)
        {
            Type actionType = discoveredEffectMethod.ActionType;

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

            Type classGenericType = typeof(EffectWrapper <>).MakeGenericType(actionType);
            var  result           = (IEffect)Activator.CreateInstance(
                classGenericType,
                effectHostInstance,
                discoveredEffectMethod);

            return(result);
        }