Ejemplo n.º 1
0
 public void Calling_IsReflectionImportDefinition_with_null_importDefinition_throws_an_exception()
 {
     Assert.That(delegate
     {
         ContractServices.IsReflectionImportDefinition(null);
     }, Throws.TypeOf <ArgumentNullException>());
 }
Ejemplo n.º 2
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);
        }