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

            return(new HandleWithActionParameterAsyncHandler((action, dispatcher) => handler.Invoke(dispatcher)));
        }
Esempio n. 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);
        }