private void debugPrintImportedCpu() { Console.WriteLine("Imported CPU List:"); for (int i = 0; i < _icpu.Count; i++) { ImportedCpu cpu = _icpu[i]; Console.WriteLine("[" + i + "]" + cpu.getName()); } }
private static List <ImportedCpu> ImportCpu() { List <ImportedCpu> cpuList = new List <ImportedCpu>(); //CPUフォルダ string rootCpuFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); rootCpuFolder += "\\cpu"; if (!Directory.Exists(rootCpuFolder)) { throw new ApplicationException("cpuフォルダ\"" + rootCpuFolder + "\"が見つかりませんでした。"); } //.dllファイルを探す string[] folders = Directory.GetDirectories(rootCpuFolder); foreach (string folder in folders) { string[] dlls = Directory.GetFiles(folder, "*.dll"); foreach (string dll in dlls) { try { //アセンブリとして読み込む Assembly asm = Assembly.LoadFrom(dll); bool isImport = true; foreach (Type t in asm.GetTypes()) { //アセンブリ内のすべての型について、 //プラグインとして有効か調べる if (t.IsClass && t.IsPublic && !t.IsAbstract && t.FullName != "Cpu.Generic.Port" && t.FullName != "Cpu.Generic.ICpu") { ImportedCpu cpu = new ImportedCpu(); cpu._cputype = t; cpuList.Add(cpu); } } } catch { } } } return(cpuList); }