This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#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<Type>();
|
||||
}
|
||||
|
||||
public Type[] InstallerTypes { get; }
|
||||
}
|
||||
|
||||
internal static class ShrinkAppGeneratedRegistry
|
||||
{
|
||||
public static IReadOnlyList<Type> GetInstallerTypes()
|
||||
{
|
||||
var types = new List<Type>();
|
||||
var seen = new HashSet<Type>();
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
object[] attributes;
|
||||
try
|
||||
{
|
||||
attributes = assembly.GetCustomAttributes(typeof(ShrinkAppInstallerRegistryAttribute), false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var attribute in attributes.OfType<ShrinkAppInstallerRegistryAttribute>())
|
||||
{
|
||||
foreach (var installerType in attribute.InstallerTypes ?? Array.Empty<Type>())
|
||||
{
|
||||
if (installerType == null || !seen.Add(installerType))
|
||||
continue;
|
||||
|
||||
types.Add(installerType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user