private static HandleWithoutActionParameterAsyncHandler CreateStaticHandlerWithoutActionParameter( DiscoveredEffectMethod discoveredEffectMethod) => (HandleWithoutActionParameterAsyncHandler) Delegate.CreateDelegate( type: typeof(HandleWithoutActionParameterAsyncHandler), method: discoveredEffectMethod.MethodInfo);
private static HandleWithoutActionParameterAsyncHandler CreateHandlerWithoutActionParameter( object effectHostInstance, DiscoveredEffectMethod discoveredEffectMethod) => effectHostInstance == null ? CreateStaticHandlerWithoutActionParameter(discoveredEffectMethod) : CreateInstanceHandlerWithoutActionParameter(effectHostInstance, discoveredEffectMethod);
public EffectWrapper(object effectHostInstance, DiscoveredEffectMethod discoveredEffectMethod) { HandleAsync = discoveredEffectMethod.RequiresActionParameterInMethod ? CreateHandlerWithActionParameter(effectHostInstance, discoveredEffectMethod) : WrapEffectWithoutActionParameter(effectHostInstance, discoveredEffectMethod);; }
private static HandleWithoutActionParameterAsyncHandler CreateInstanceHandlerWithoutActionParameter( object effectHostInstance, DiscoveredEffectMethod discoveredEffectMethod) => (HandleWithoutActionParameterAsyncHandler) Delegate.CreateDelegate( type: typeof(HandleWithoutActionParameterAsyncHandler), firstArgument: effectHostInstance, method: discoveredEffectMethod.MethodInfo);
private static HandleWithActionParameterAsyncHandler WrapEffectWithoutActionParameter( object effectHostInstance, DiscoveredEffectMethod discoveredEffectMethod) { HandleWithoutActionParameterAsyncHandler handler = CreateHandlerWithoutActionParameter( effectHostInstance, discoveredEffectMethod); return(new HandleWithActionParameterAsyncHandler((action, dispatcher) => handler.Invoke(dispatcher))); }
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); }