#nullable enable using System; using System.Collections.Generic; using System.Linq; namespace ShrinkEventBus { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] public sealed class EventBusStaticRegistryAttribute : Attribute { public EventBusStaticRegistryAttribute(params Type[] subscriberTypes) { SubscriberTypes = subscriberTypes ?? Array.Empty(); } public Type[] SubscriberTypes { get; } } internal static class EventBusGeneratedRegistry { public static IReadOnlyList GetStaticSubscriberTypes() { var types = new List(); var seen = new HashSet(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { object[] attributes; try { attributes = assembly.GetCustomAttributes(typeof(EventBusStaticRegistryAttribute), false); } catch { continue; } foreach (var attribute in attributes.OfType()) { foreach (var subscriberType in attribute.SubscriberTypes ?? Array.Empty()) { if (subscriberType == null || !seen.Add(subscriberType)) continue; types.Add(subscriberType); } } } return types; } } }