From abcd0e0d6cb5532c8a19a8cd8c7dd83e7f143442 Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 11 Sep 2024 16:43:20 -0400 Subject: Managed library & package updates --- lib/Plugins.Runtime/src/LivePlugin.cs | 40 ++++++++++------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'lib/Plugins.Runtime') diff --git a/lib/Plugins.Runtime/src/LivePlugin.cs b/lib/Plugins.Runtime/src/LivePlugin.cs index 3ed2ad6..26276dd 100644 --- a/lib/Plugins.Runtime/src/LivePlugin.cs +++ b/lib/Plugins.Runtime/src/LivePlugin.cs @@ -26,6 +26,7 @@ using System; using System.Linq; using System.Reflection; +using VNLib.Utils.Resources; using VNLib.Plugins.Attributes; namespace VNLib.Plugins.Runtime @@ -76,18 +77,14 @@ namespace VNLib.Plugins.Runtime Plugin = plugin; OriginAsm = originAsm; PluginType = plugin.GetType(); - GetConsoleHandler(); + PluginConsoleHandler = GetConsoleHandler(plugin); } - private void GetConsoleHandler() + private static ConsoleEventHandlerSignature? GetConsoleHandler(IPlugin plugin) { - //Get the console handler method from the plugin instance - MethodInfo? handler = (from m in PluginType.GetMethods() - where m.GetCustomAttribute() != null - select m) - .FirstOrDefault(); //Get a delegate handler for the plugin - PluginConsoleHandler = handler?.CreateDelegate(Plugin); + return ManagedLibrary.GetMethodsWithAttribute(plugin) + .FirstOrDefault(); } /// @@ -97,18 +94,9 @@ namespace VNLib.Plugins.Runtime /// The host configuration DOM internal void InitConfig(ReadOnlySpan configData) { - //Get the console handler method from the plugin instance - MethodInfo? confHan = PluginType.GetMethods().Where(static m => m.GetCustomAttribute() != null) - .FirstOrDefault(); - //Get a delegate handler for the plugin - ConfigInitializer? configInit = confHan?.CreateDelegate(Plugin); - if (configInit == null) - { - return; - } - - //Invoke - configInit.Invoke(configData); + ManagedLibrary.GetMethodsWithAttribute(Plugin!) + .FirstOrDefault() + ?.Invoke(configData); } /// @@ -118,15 +106,9 @@ namespace VNLib.Plugins.Runtime /// The current process's CLI args internal void InitLog(string[] cliArgs) { - //Get the console handler method from the plugin instance - MethodInfo? logInit = (from m in PluginType.GetMethods() - where m.GetCustomAttribute() != null - select m) - .FirstOrDefault(); - //Get a delegate handler for the plugin - LogInitializer? logFunc = logInit?.CreateDelegate(Plugin); - //Invoke - logFunc?.Invoke(cliArgs); + ManagedLibrary.GetMethodsWithAttribute(Plugin!) + .FirstOrDefault() + ?.Invoke(cliArgs); } /// -- cgit