public void AllTest() { var options = new AssembliesOptions(); //options.AssemblyLoadPath = PathExtensions.CurrentDirectory; // 设定筛选器描述符 var librameFiltering = new AssembliesFilteringDescriptor("LibrameFiltering"); // 包含 Librame librameFiltering.Filters.Add(new FilteringRegex("Librame", FilteringMode.Inclusive)); // 排除 Tests librameFiltering.Filters.Add(new FilteringRegex("Tests", FilteringMode.Exclusive)); options.FilteringDescriptors.Add(librameFiltering); var instantiator = new AssembliesInstantiator(options); var assemblies = instantiator.Create(); Assert.NotEmpty(assemblies); var keyTypes = assemblies.ExportedConcreteTypes <TypeNamedKey>(); Assert.NotEmpty(keyTypes); var attribTypes = assemblies.ExportedConcreteTypesByAttribute <NotMappedAttribute>(); Assert.NotEmpty(attribTypes); }
/// <summary> /// 解析插件信息列表。 /// </summary> /// <returns>返回 <see cref="IReadOnlyList{IPluginInfo}"/>。</returns> /// <exception cref="DllNotFoundException"></exception> public IReadOnlyList <IPluginInfo> ResolveInfos() { if (_infos is null) { var instantiator = new AssembliesInstantiator(_options.AssemblyLoading); var infoTypes = instantiator.Create().ExportedConcreteTypes <IPluginInfo>().ToArray(); if (infoTypes is null || infoTypes.Length < 1) { throw new DllNotFoundException($"The plugin assembly implementing {nameof(IPluginInfo)} was not found, please confirm that any plugin package is installed."); } _infos = infoTypes.Select(s => (IPluginInfo)s.NewByExpression()).ToList(); if (_infos.Count > 1) { _infos.Sort(); } } return(_infos); }