private static void LoadDerivedTypeInOneFolder(Type baseType, ICollection <Type> derivedTypeList, string folderPath, bool copyToMemory) { var files = Directory.GetFiles(folderPath); foreach (var file in files) { if (!file.EndsWith(TARGET_FILE_POSTFIX)) { continue; } Assembly asm = null; #region Asm try { if (copyToMemory) { var pluginStream = FileUtil.Read(file); asm = Assembly.Load(pluginStream); } else { asm = Assembly.LoadFrom(file); } } catch (Exception) { // ignore; } if (asm == null) { continue; } #endregion var types = asm.GetTypes(); foreach (var t in types) { if (t.IsSubclassOf(baseType) || baseType.IsAssignableFrom(t)) { if (!t.IsAbstract) { derivedTypeList.Add(t); } } } } }
/// <summary> /// ReadFromFile 从文件读取二进制反序列化为对象。 /// </summary> public static object ReadFromFile(string filePath) { byte[] buff = FileUtil.Read(filePath); return(DeserializeBytes(buff, 0, buff.Length)); }