From 99ee34b08f8b08ab6aea6e0c32dd09b176eefa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E7=9A=84=E6=AF=8D=E9=B8=A1?= <710521324@qq.com> Date: Tue, 28 Feb 2023 13:05:11 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 加载dll/Program.cs | 4 ++-- 加载dll/加载插件上下文.cs | 16 ---------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/加载dll/Program.cs b/加载dll/Program.cs index acbb35c..4107d08 100644 --- a/加载dll/Program.cs +++ b/加载dll/Program.cs @@ -83,7 +83,7 @@ namespace 加载Dll string pluginLocation = Path.GetFullPath(Path.Combine(root, 相对路径.Replace('\\', Path.DirectorySeparatorChar))); Console.WriteLine($"加载插件: {pluginLocation}"); - 加载插件上下文 loadContext = new 加载插件上下文(pluginLocation); + 加载插件上下文 loadContext = new(pluginLocation); return loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(pluginLocation))); } @@ -95,7 +95,7 @@ namespace 加载Dll { if (typeof(ICommand).IsAssignableFrom(type)) { - ICommand result = Activator.CreateInstance(type) as ICommand; + ICommand? result = Activator.CreateInstance(type) as ICommand; if (result != null) { count++; diff --git a/加载dll/加载插件上下文.cs b/加载dll/加载插件上下文.cs index 3c6977d..ba27aa2 100644 --- a/加载dll/加载插件上下文.cs +++ b/加载dll/加载插件上下文.cs @@ -40,22 +40,6 @@ namespace 加载dll return IntPtr.Zero; } - - static Assembly LoadPlugin(string relativePath) - { - // Navigate up to the solution root - string root = Path.GetFullPath(Path.Combine( - Path.GetDirectoryName( - Path.GetDirectoryName( - Path.GetDirectoryName( - Path.GetDirectoryName( - Path.GetDirectoryName(typeof(Program).Assembly.Location))))))); - - string pluginLocation = Path.GetFullPath(Path.Combine(root, relativePath.Replace('\\', Path.DirectorySeparatorChar))); - Console.WriteLine($"Loading commands from: {pluginLocation}"); - 加载插件上下文 loadContext = new 加载插件上下文(pluginLocation); - return loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(pluginLocation))); - } } }