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