public static IManuallyConfigureEventAppliers WithAnyAppliersFromInstances( this IManuallyConfigureEventAppliers self, IEnumerable <object> appliers) { var applierList = appliers?.ToList() ?? new List <object>(); if (applierList.Any(x => x == null)) { throw new ArgumentNullException(nameof(appliers), "The list of appliers may not contain a null applier."); } var applyEventInterfaceDefinitions = applierList.Select(x => new { Type = x.GetType(), Instance = x }) .SelectMany(x => x.Type.GetInterfaces().Select(i => new { Interface = i, x.Instance })) .Where(x => x.Interface.IsGenericType) .Where(x => x.Interface.GetGenericTypeDefinition() == openApplierType || x.Interface.GetGenericTypeDefinition() == openEventApplierType); foreach (var applierTypeInfo in applyEventInterfaceDefinitions) { if (applierTypeInfo.Interface.GetGenericTypeDefinition() == openApplierType) { //We have IApplyEvents<> var stateType = applierTypeInfo.Interface.GetGenericArguments()[0]; self.WithEventApplier(stateType, applierTypeInfo.Instance); } else if (applierTypeInfo.Interface.GetGenericTypeDefinition() == openEventApplierType) { //We have IApplyEvent<,> var stateType = applierTypeInfo.Interface.GetGenericArguments()[0]; var eventType = applierTypeInfo.Interface.GetGenericArguments()[1]; self.WithEventApplier(stateType, eventType, applierTypeInfo.Instance); } } return(self); }
public static IManuallyConfigureEventAppliers WithEventApplier <TState, TEvent>(this IManuallyConfigureEventAppliers self, IApplyEvent <TState, TEvent> stateApplier) => self.WithEventApplier((FuncEventApplier <TState, TEvent>)stateApplier.Apply);
public static IManuallyConfigureEventAppliers WithEventApplier <TState, TEvent>(this IManuallyConfigureEventAppliers self, Func <TState, TEvent, TState> stateApplier) => self.WithEventApplier((FuncEventApplier <TState, TEvent>)stateApplier);