C# 反射使用使用外部DLL

 1 private void Init()
 2         {
 3             string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
 4             string dllPath = path + @"\CefWebBorwser\" + "CefWebBrowserControl.dll";
 5             if (System.IO.File.Exists(dllPath))
 6             {
 7                 Assembly assembly = Assembly.LoadFrom(dllPath);
 8                 Type browserType = assembly.GetType("CefWebBrowserControl.CefWebBrowser");
 9                 object browserObj = System.Activator.CreateInstance(browserType);
10                 MethodInfo method = browserType.GetMethod("OpenUrl");
11                 string dataStatisticUrl = $"http://{UserHelper.Instance.CurrentUser.ServerIp}:{UserHelper.Instance.CurrentUser.WebPort}/#/login.html?userSession={_websocketService.GetSession()}&lang={GetLang()}&route=2";
12                 CommonHelper.LogDebug("dataStatisticUrl:" + dataStatisticUrl);
13                 method.Invoke(browserObj, new object[] { dataStatisticUrl });
14                 System.Windows.Forms.UserControl browser = (System.Windows.Forms.UserControl)browserObj;
15                 browser.Dock = DockStyle.Fill;
16                 host.Child = browser;
17             }
18         }

猜你喜欢

转载自www.cnblogs.com/yuanchao/p/12104119.html