mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-12 20:17:22 +01:00
make mare less dumpy
This commit is contained in:
parent
925bf7e6c6
commit
89f7b1737e
3 changed files with 29 additions and 23 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronos.Services.Mediator;
|
||||
|
|
@ -15,7 +16,7 @@ public sealed class MareMediator : IHostedService
|
|||
private readonly PerformanceCollectorService _performanceCollector;
|
||||
private readonly Dictionary<Type, HashSet<SubscriberAction>> _subscriberDict = [];
|
||||
private bool _processQueue = false;
|
||||
|
||||
private readonly Dictionary<Type, MethodInfo?> _genericExecuteMethods = new();
|
||||
public MareMediator(ILogger<MareMediator> logger, PerformanceCollectorService performanceCollector)
|
||||
{
|
||||
_logger = logger;
|
||||
|
|
@ -143,10 +144,15 @@ public sealed class MareMediator : IHostedService
|
|||
}
|
||||
|
||||
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
GetType()
|
||||
.GetMethod(nameof(ExecuteReflected), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?
|
||||
.MakeGenericMethod(message.GetType())?
|
||||
.Invoke(this, [subscribersCopy, message]);
|
||||
var msgType = message.GetType();
|
||||
if (!_genericExecuteMethods.TryGetValue(msgType, out var methodInfo))
|
||||
{
|
||||
_genericExecuteMethods[message.GetType()] = methodInfo = GetType()
|
||||
.GetMethod(nameof(ExecuteReflected), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?
|
||||
.MakeGenericMethod(msgType);
|
||||
}
|
||||
|
||||
methodInfo!.Invoke(this, [subscribersCopy, message]);
|
||||
#pragma warning restore S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue