private IEnumerable <Export> InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) { ThrowIfDisposed(); EnsureRunning(); // Use the version of the catalog appropriate to this atomicComposition ComposablePartCatalog currentCatalog = atomicComposition.GetValueAllowNull(_catalog); IPartCreatorImportDefinition partCreatorDefinition = definition as IPartCreatorImportDefinition; bool isExportFactory = false; if (partCreatorDefinition != null) { definition = partCreatorDefinition.ProductImportDefinition; isExportFactory = true; } CreationPolicy importPolicy = definition.GetRequiredCreationPolicy(); List <Export> exports = new List <Export>(); bool ensureRejection = EnsureRejection(atomicComposition); foreach (var partDefinitionAndExportDefinition in currentCatalog.GetExports(definition)) { bool isPartRejected = ensureRejection && IsRejected(partDefinitionAndExportDefinition.Item1, atomicComposition); if (!isPartRejected) { exports.Add(CreateExport(partDefinitionAndExportDefinition.Item1, partDefinitionAndExportDefinition.Item2, isExportFactory, importPolicy)); } } return(exports); }
/// <summary> /// Returns the export definitions that match the constraint defined by the specified definition. /// </summary> /// <param name="definition">The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="ExportDefinition"/> objects to return.</param> /// <returns> /// An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the /// <see cref="ExportDefinition"/> objects and their associated /// <see cref="ComposablePartDefinition"/> for objects that match the constraint defined /// by <paramref name="definition"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="definition"/> is <see langword="null"/>. /// </exception> /// <exception cref="ObjectDisposedException"> /// The <see cref="ComposablePartCatalog"/> has been disposed of. /// </exception> /// <remarks> /// <note type="inheritinfo"> /// Overriders of this property should never return <see langword="null"/>, if no /// <see cref="ExportDefinition"/> match the conditions defined by /// <paramref name="definition"/>, return an empty <see cref="IEnumerable{T}"/>. /// </note> /// </remarks> public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition) { ThrowIfDisposed(); Requires.NotNull(definition, nameof(definition)); var exports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>(); foreach (var export in _innerCatalog.GetExports(definition)) { if (_filter(export.Item1)) { exports.Add(export); } } return exports; }
/// <summary> /// Returns all exports that match the conditions of the specified import. /// </summary> /// <param name="definition">The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="Export"/> to get.</param> /// <returns></returns> /// <result> /// An <see cref="IEnumerable{T}"/> of <see cref="Export"/> objects that match /// the conditions defined by <see cref="ImportDefinition"/>, if found; otherwise, an /// empty <see cref="IEnumerable{T}"/>. /// </result> /// <remarks> /// <note type="inheritinfo"> /// The implementers should not treat the cardinality-related mismatches as errors, and are not /// expected to throw exceptions in those cases. /// For instance, if the import requests exactly one export and the provider has no matching exports or more than one, /// it should return an empty <see cref="IEnumerable{T}"/> of <see cref="Export"/>. /// </note> /// </remarks> protected override IEnumerable <Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) { this.ThrowIfDisposed(); this.EnsureRunning(); // Use the version of the catalog appropriate to this atomicComposition ComposablePartCatalog currentCatalog = atomicComposition.GetValueAllowNull(this._catalog); #if SILVERLIGHT IPartCreatorImportDefinition partCreatorDefinition = definition as IPartCreatorImportDefinition; bool isPartCreator = false; if (partCreatorDefinition != null) { definition = partCreatorDefinition.ProductImportDefinition; isPartCreator = true; } #endif CreationPolicy importPolicy = definition.GetRequiredCreationPolicy(); List <Export> exports = new List <Export>(); foreach (var partDefinitionAndExportDefinition in currentCatalog.GetExports(definition)) { if (!IsRejected(partDefinitionAndExportDefinition.Item1, atomicComposition)) { #if SILVERLIGHT if (isPartCreator) { exports.Add(new PartCreatorExport(this, partDefinitionAndExportDefinition.Item1, partDefinitionAndExportDefinition.Item2)); } else #endif { exports.Add(CatalogExport.CreateExport(this, partDefinitionAndExportDefinition.Item1, partDefinitionAndExportDefinition.Item2, importPolicy)); } } } return(exports); }
public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports( ImportDefinition definition) { Requires.NotNull(definition, nameof(definition)); var originalExports = _originalCatalog.GetExports(definition); var trimmedExports = originalExports.Where(partAndExport => !_removedParts.Contains(partAndExport.Item1)); var addedExports = new List <Tuple <ComposablePartDefinition, ExportDefinition> >(); foreach (var part in _addedParts) { foreach (var export in part.ExportDefinitions) { if (definition.IsConstraintSatisfiedBy(export)) { addedExports.Add(new Tuple <ComposablePartDefinition, ExportDefinition>(part, export)); } } } return(trimmedExports.Concat(addedExports)); }
/// <summary> /// Returns the export definitions that match the constraint defined by the specified definition. /// </summary> /// <param name="definition">The <see cref="ImportDefinition"/> that defines the conditions of the /// <see cref="ExportDefinition"/> objects to return.</param> /// <returns> /// An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the /// <see cref="ExportDefinition"/> objects and their associated /// <see cref="ComposablePartDefinition"/> for objects that match the constraint defined /// by <paramref name="definition"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="definition"/> is <see langword="null"/>. /// </exception> /// <exception cref="ObjectDisposedException"> /// The <see cref="ComposablePartCatalog"/> has been disposed of. /// </exception> /// <remarks> /// <note type="inheritinfo"> /// Overriders of this property should never return <see langword="null"/>, if no /// <see cref="ExportDefinition"/> match the conditions defined by /// <paramref name="definition"/>, return an empty <see cref="IEnumerable{T}"/>. /// </note> /// </remarks> public override IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition) { ThrowIfDisposed(); return(_catalog.GetExports(definition)); }