private static Dictionary <Tuple <Type, string>, Type> BuildCommandTypeIndex() { return(Discover.ConcreteTypesDerivedFrom(typeof(ICommand)) .Select(commandType => new { commandType, targetType = commandType.GetInterface("ICommand`1") .IfNotNull() .Then(i => i.GetGenericArguments().Single()) .ElseDefault() }) .ToDictionary( p => Tuple.Create(p.targetType, p.commandType.Name), p => p.commandType)); }
internal static Type[] ConcreteTypesOf(Type eventType) { var types = Discover.ConcreteTypesDerivedFrom(eventType); if (!typeof(IScheduledCommand).IsAssignableFrom(eventType)) { return(types.ToArray()); } if (eventType.IsGenericType) { var type = typeof(CommandScheduled <>).MakeGenericType(eventType.GetGenericArguments()); return(types.Concat(new[] { type }) .Distinct() .ToArray()); } return(types.Concat(AggregateType.KnownTypes.Select(t => typeof(CommandScheduled <>).MakeGenericType(t)).ToArray()) .Distinct() .ToArray()); }
/// <summary> /// Returns all known concrete event types. /// </summary> public static IEnumerable <Type> KnownTypes() => Discover.ConcreteTypesDerivedFrom(typeof(IEvent));