/// <summary> /// 在指定的模块中根据插件类型获取插件类 /// </summary> /// <param name="model"></param> /// <param name="Type"></param> /// <returns></returns> public static List <Type> GetTypesByType(this System.Reflection.Assembly model, string Type = "") { List <Type> lstType = new List <Type>(); var types = model.GetExportedTypes(); if (String.IsNullOrWhiteSpace(Type)) { Type = model.GetAssemblyPluginAttribute().Type; } foreach (var type in types) { //System.Threading.Tasks.Parallel.ForEach(types, type => //{ var pluginAttribute = type.GetPluginAttribute(); if (!String.IsNullOrWhiteSpace(Type) && pluginAttribute != null && pluginAttribute.Type.ToLower() == Type.ToLower()) { lstType.Add(type); } if (pluginAttribute != null && String.IsNullOrWhiteSpace(pluginAttribute.Type)) { lstType.Add(type); } //}); } return(lstType); }
/// <summary> /// 在指定的模块中根据插件ID获取插件类 /// </summary> /// <param name="model"></param> /// <param name="PluginId"></param> /// <returns></returns> public static Type GetTypeByPluginId(this System.Reflection.Assembly model, string PluginId = "") { var types = model.GetExportedTypes(); if (String.IsNullOrWhiteSpace(PluginId)) { PluginId = model.GetAssemblyPluginAttribute().DefaultPluginID; } if (String.IsNullOrWhiteSpace(PluginId)) { return(null); } var existType = types.FirstOrDefault(type => { var pluginAttribute = type.GetPluginAttribute(); if (pluginAttribute != null) { return(pluginAttribute.ID.ToLower() == PluginId.ToLower()); } else { return(false); } }); return(existType); }