using System.Collections.Generic; using System.Linq; using Core.Common.Utils.Reflection; namespace Core.Common.Base { public static class ApplicationCoreExtensions { public static IList GetImporters(this ApplicationCore applicationCore, object target) { var targetType = target == null ? null : target.GetType(); IList importers = new List(); foreach (IFileImporter importer in applicationCore.Plugins.SelectMany(plugin => plugin.GetFileImporters())) { if (targetType == null && !importer.CanImportOnRootLevel) { //this importer requires something to import into, but we're importing globally (into project or folder), so skip it continue; } // filter importers only to those which can import into targetType if ((targetType == null) || (importer.SupportedItemTypes.Any(t => (t == targetType) || targetType.Implements(t)) && importer.CanImportOn(target))) { importers.Add(importer); } } return importers; } public static IEnumerable GetSupportedExportersForItem(this ApplicationCore applicationCore, object itemToExport) { var sourceType = itemToExport.GetType(); return applicationCore.Plugins.SelectMany(plugin => plugin.GetFileExporters()) .Where(e => e.SourceTypes().Any(type => type == sourceType || type.IsAssignableFrom(sourceType)) && e.CanExportFor(itemToExport)); } } }