|
|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace MyFrist
- {
- interface Test
- {
- int Add(int a, int b);
- }
- class Hei : Test
- {
- public int Add(int a, int b)
- {
- try
- {
- return a + b;
- }
- catch (Exception ex)
- {
- return 0;
- }
- }
- }
- }
复制代码
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleDll
- {
- class Program
- {
- static void Main(string[] args)
- {
- string dllPath = AppDomain.CurrentDomain.BaseDirectory + "MyFrist.dll";
- var resource = System.Reflection.Assembly.LoadFrom(dllPath);
- foreach (var _every in resource.GetTypes())
- {
- if (_every.GetInterface("Test") != null)
- {
- var plugin = Activator.CreateInstance(_every);
- object[] paramertors = new object[] { 500, 2 };//参数集合
- var temp=_every.GetMethod("Add");
- object result=temp.Invoke(plugin, paramertors);
- Console.WriteLine(result);
- }
- }
- }
- }
- }
复制代码
|
上一篇:c# 抓取网页的img src带参数的图片链接,并下载下一篇:mvc 用websocket连接不上的错误原因!
|