1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| string dllPath = System.Environment.CurrentDirectory;
string[] files = Directory.GetFiles(dllPath); foreach(string file in files) { if (!file.Contains(".dll")) continue; Assembly ass = Assembly.LoadFile(file); Type[] types = ass.GetTypes(); object obj = null; foreach (Type t in types) { if(typeof(InterfaceBase).IsAssignableFrom(t)) { obj = ass.CreateInstance(t.FullName, true); } if (obj is InterfaceBase) { InterfaceBase ib = obj as InterfaceBase; ib.DoSomething(); } } }
|