hopefully not a horribly foolish refactoring

This commit is contained in:
john 2025-05-11 23:26:09 +02:00
parent 59d660165f
commit 1ecaf64dea
82 changed files with 782 additions and 398 deletions

View file

@ -0,0 +1,37 @@
using System.Reflection;
using Femto.Common.Attributes;
using MediatR;
namespace Femto.Common.Util;
public static class EventTypeMapping
{
public static IDictionary<string, Type> GetEventTypeMapping(Assembly assembly)
{
var mapping = new Dictionary<string, Type>();
var types = assembly.GetTypes();
foreach (var type in types)
{
if (
!typeof(INotification).IsAssignableFrom(type)
|| type.IsAbstract
|| type.IsInterface
)
continue;
var attribute = type.GetCustomAttribute<EventTypeAttribute>();
if (attribute == null)
continue;
var eventName = attribute.Name;
if (!string.IsNullOrWhiteSpace(eventName))
{
mapping.TryAdd(eventName, type);
}
}
return mapping;
}
}