Exemplo n.º 1
0
        private Export CreateExport(ComposablePartDefinition partDefinition,
                                    ExportDefinition exportDefinition, ImportDefinition importDefinition)
        {
            CreationPolicy importPolicy = importDefinition.GetRequiredCreationPolicy();

            return(CatalogExport.CreateExport(this, partDefinition, exportDefinition, importPolicy));
        }
 private Export CreateExport(ComposablePartDefinition partDefinition, ExportDefinition exportDefinition, bool isExportFactory, CreationPolicy importPolicy)
 {
     if (isExportFactory)
     {
         return(new PartCreatorExport(this,
                                      partDefinition,
                                      exportDefinition));
     }
     else
     {
         return(CatalogExport.CreateExport(this,
                                           partDefinition,
                                           exportDefinition,
                                           importPolicy));
     }
 }
Exemplo n.º 3
0
        /// <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);
        }