| | | 1 | | using System.Collections.Concurrent; |
| | | 2 | | |
| | | 3 | | namespace Syki.Back.Events; |
| | | 4 | | |
| | | 5 | | public static class DomainEventMapper |
| | | 6 | | { |
| | 0 | 7 | | private static readonly ConcurrentDictionary<string, DomainEventAttribute> _attributes = new(); |
| | | 8 | | |
| | | 9 | | public static string ToDomainEventDescription(this string value) |
| | | 10 | | { |
| | 0 | 11 | | if (value.IsEmpty()) return value; |
| | | 12 | | |
| | 0 | 13 | | return _attributes.GetOrAdd(value, GetDomainEventAttribute(value)).Description; |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | public static string ToDomainEventEntityName(this string value) |
| | | 17 | | { |
| | 0 | 18 | | if (value.IsEmpty()) return value; |
| | | 19 | | |
| | 0 | 20 | | return _attributes.GetOrAdd(value, GetDomainEventAttribute(value)).Entity; |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | private static DomainEventAttribute GetDomainEventAttribute(this string value) |
| | | 24 | | { |
| | 0 | 25 | | var type = typeof(IDomainEvent).Assembly.GetType(value)!; |
| | 0 | 26 | | var customAttributes = (DomainEventAttribute[])type.GetCustomAttributes(typeof(DomainEventAttribute), true); |
| | 0 | 27 | | return customAttributes[0]; |
| | | 28 | | } |
| | | 29 | | } |