/// <summary>
        /// Initializes a new instance of the <see cref="XElementExportProvider"/> class.
        /// Includes *.xml and *.config by default.
        /// </summary>
        /// <param name="path">The path. Defaults to Directory.GetCurrentDirectory()</param>
        /// <param name="filters">A list of additional file filters to include.</param>
        public XElementExportProvider(string path = null, IEnumerable<string> filters = null)
        {
            if (path == null)
            {
                path = Directory.GetCurrentDirectory();
            }
            List<string> include = new List<string>(new[] { "*.xml", "*.config" });
            if (filters != null)
            {
                foreach (string filter in filters.Where(filter => !string.IsNullOrWhiteSpace(filter)).Where(filter => !include.Contains(filter)))
                {
                    include.Add(filter);
                }
            }

            List<string> xmlFiles = new List<string>(include.SelectMany(ext => Directory.GetFiles(path, ext)));

            _exportsDictionary = xmlFiles.Select(filePath => new FileInfo(filePath)).ToDictionary(
                fileInfo => fileInfo.Name,
                fileInfo =>
                {
                    ExportDefinition def = new ExportDefinition(fileInfo.Name, null);
                    Export e = new Export(def, () => XElement.Load(fileInfo.FullName));
                    return e;
                });
        }
Ejemplo n.º 2
0
        public System.ComponentModel.Composition.Primitives.ComposablePart AddExport(System.ComponentModel.Composition.Primitives.Export export)
        {
            Contract.Requires(export != null);
            Contract.Ensures(Contract.Result <System.ComponentModel.Composition.Primitives.ComposablePart>() != null);

            return(default(System.ComponentModel.Composition.Primitives.ComposablePart));
        }
 public void GetExportedObject_Guards_Against_Non_Matching_ExportDefinition()
 {
     object expected = new object();
     Export export = new Export("Foo", new Dictionary<string, object>(), () => expected);
     ExportDefinition nonMatching = new ExportDefinition("Bar", new Dictionary<string, object>());
     ExceptionAssert.Guards(() => new SingleExportComposablePart(export).GetExportedObject(nonMatching),
                            TargetResources.Error_PartDoesNotContainAnExportForContract, nonMatching.ContractName);
 }
 public void SetImport_Throws_InvalidOperationException()
 {
     Export export = new Export("Foo", new Dictionary<string, object>(), () => null);
     ExceptionAssert.Guards(() => new SingleExportComposablePart(export).SetImport(null, null),
                            TargetResources.Error_PartDoesNotContainAnyImports);
 }
 public void Part_Has_No_Imports()
 {
     Export export = new Export("Foo", new Dictionary<string, object>(), () => null);
     Assert.AreEqual(0, new SingleExportComposablePart(export).ImportDefinitions.Count());
 }
 public void GetExportedObject_Returns_Exported_Object_If_ExportDefinition_Matches_Single_Export()
 {
     object expected = new object();
     Export export = new Export("Foo", new Dictionary<string, object>(), () => expected);
     Assert.AreSame(expected, new SingleExportComposablePart(export).GetExportedObject(export.Definition));
 }
 public void Constructor_Sets_ExportDefinitions_To_Single_Export()
 {
     Export export = new Export("Foo", new Dictionary<string, object>(), () => null);
     Assert.AreSame(export.Definition, new SingleExportComposablePart(export).ExportDefinitions.Single());
 }