Пример #1
0
        public static List <PluginAnalysis> GetPluginAnalysis(PluginAnalyses pluginAnalyses)
        {
            List <PluginAnalysis> plugins = new List <PluginAnalysis>();

            foreach (var dllModule in pluginAnalyses.PluginAssembly.GetLoadedModules())
            {
                foreach (var typeDefinedInModule in dllModule.GetTypes())
                {
                    if (typeDefinedInModule.IsClass)
                    {
                        var plugin = new PluginAnalysis();
                        plugin.IsPlugin = typeDefinedInModule.GetInterfaces().Contains(typeof(IAbsPlugin));
                        if (plugin.IsPlugin)
                        {
                            foreach (var _interface in pluginAnalyses.Instances)
                            {
                                if (typeDefinedInModule.GetInterfaces().Select(x => x.GUID).Contains(_interface.GUID))
                                {
                                    plugin.PluginInstances.Add(ConvertToInstanceInfo(_interface));
                                }
                            }
                        }

                        plugin.Plugin = ConvertToPluginInfo(typeDefinedInModule);

                        plugins.Add(plugin);
                    }
                }
            }
            return(plugins);
        }
Пример #2
0
        public static PluginAnalyses Load(string filePath)
        {
            if (System.IO.File.Exists(filePath))
            {
                FileInfo fileInfo = new FileInfo(filePath);
                if (fileInfo.Extension.ToLower() == ".dll")
                {
                    PluginAnalyses pluginAnalyses = new PluginAnalyses();
                    pluginAnalyses.FilePath       = fileInfo.FullName;
                    pluginAnalyses.PluginAssembly = Assembly.Load(ReadFile(fileInfo.FullName).ToArray());
                    pluginAnalyses.Instances      = GetInstances();

                    return(pluginAnalyses);
                }
                else
                {
                    throw new XmsException("文件类型不正确");
                }
            }
            else
            {
                throw new XmsException("未找到相关{" + filePath + "}文件");
            }
        }