public void Calling_GetImportDefinitionType_with_null_importDefinition_throws_an_exception()
 {
     Assert.That(delegate
     {
         ContractServices.GetImportDefinitionType(null);
     }, Throws.TypeOf <ArgumentNullException>());
 }
        public IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition, IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > exports)
        {
            if (!exports.Any())
            {
                exports = this.catalog.GetExports(definition);
            }

            if (exports.Any())
            {
                return(exports);
            }

            var returnedExports      = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();
            var importDefinitionType = ContractServices.GetImportDefinitionType(definition);

            if (!importDefinitionType.IsAbstract && !importDefinitionType.IsInterface)
            {
                var typeCatalog = new TypeCatalog(importDefinitionType);
                this.catalog.Catalogs.Add(typeCatalog);
                var currentExports = this.catalog.GetExports(definition);
                returnedExports.AddRange(currentExports);
            }

            return(returnedExports);
        }
Esempio n. 3
0
        /// <summary>
        /// Method which can filter exports for given <see cref="ImportDefinition"/> or produce new exports.
        /// </summary>
        /// <param name="definition"><see cref="ImportDefinition"/> instance.</param>
        /// <param name="exports">A collection of <see cref="ExportDefinition"/>
        /// instances along with their <see cref="ComposablePartDefinition"/> instances which match given <see cref="ImportDefinition"/>.</param>
        /// <returns>A collection of <see cref="ExportDefinition"/>
        /// instances along with their <see cref="ComposablePartDefinition"/> instances which match given <see cref="ImportDefinition"/>.</returns>
        public IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition, IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > exports)
        {
            if (exports.Any())
            {
                return(exports);
            }

            if (!ContractServices.IsReflectionImportDefinition(definition))
            {
                return(Enumerable.Empty <Tuple <ComposablePartDefinition, ExportDefinition> >());
            }

            var returnedExports      = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();
            var importDefinitionType = ContractServices.GetImportDefinitionType(definition);

            if (TypeHelper.IsGenericCollection(importDefinitionType))
            {
                importDefinitionType = TypeHelper.GetGenericCollectionParameter(importDefinitionType);
            }

            if (this.manufacturedParts.Contains(importDefinitionType))
            {
                returnedExports.AddRange(this.aggregateCatalog.GetExports(definition));
            }
            else if (TypeHelper.ShouldCreateClosedGenericPart(importDefinitionType))
            {
                CreateGenericParts(importDefinitionType);
                returnedExports.AddRange(this.aggregateCatalog.GetExports(definition));
            }

            return(returnedExports);
        }
 public void When_retrieving_import_definition_typoe_for_field_import_import_3_DummyImport3_is_returned()
 {
     ImportDefinition = DummyPartImports.Single(d => d.ContractName == AttributedModelServices.GetContractName(typeof(IDummyImport3)));
     Assert.AreEqual(typeof(IDummyImport3), ContractServices.GetImportDefinitionType(ImportDefinition));
 }