protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            if (definition.Cardinality != ImportCardinality.ExactlyOne)
            {
                return Enumerable.Empty<Export>();
            }

            ExportSource exportSource;
            if (_exactlyOneExports.TryGetValue(definition.ContractName, out exportSource))
            {
                AddMemberType(exportSource, definition);
                return new[] { exportSource.Export };
            }

            string typeName = ImportDefinitionConstraintAnalyser.GetRequiredTypeIdentity(definition.Constraint);
            Type type = GetType(typeName);
            if (!CanHandleType(type))
            {
                return Enumerable.Empty<Export>();
            }

            exportSource = new ExportSource(definition.ContractName, definition.Metadata);
            exportSource.AddType(type);
            AddMemberType(exportSource, definition);

            _exactlyOneExports[definition.ContractName] = exportSource;
            return new[] { exportSource.Export };
        }
        public override System.Collections.Generic.IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            var exports = base.GetExports(definition);
            if (GalaSoft.MvvmLight.ViewModelBase.IsInDesignModeStatic)
            {
                var designExports = exports.Where(export => (export.Item2.Metadata.ContainsKey(DesignTimeExportAttribute.DesignTimeMetadataName) &&
                    ((bool)export.Item2.Metadata[DesignTimeExportAttribute.DesignTimeMetadataName]) == true));

                if (designExports.Count() > 0)
                {
                    exports = designExports;
                }
                else
                {
                    exports = from export in exports
                              let ed = export.Item2
                              where !ed.Metadata.ContainsKey(DesignTimeExportAttribute.DesignTimeMetadataName)
                              select export;
                }
            }
            else
            {
                exports = from export in exports
                          let ed = export.Item2
                          where !ed.Metadata.ContainsKey(DesignTimeExportAttribute.DesignTimeMetadataName) || ((bool)ed.Metadata[DesignTimeExportAttribute.DesignTimeMetadataName]) == false
                          select export;
            }
            var a = exports.ToArray();
            return exports;
        }
Exemple #3
0
 public override IEnumerable<TempTuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
 {
     LambdaExpression lambda = definition.Constraint;
     if (lambda.Body is BinaryExpression)
     {
         BinaryExpression binaryExpression = (BinaryExpression)lambda.Body;
         if (binaryExpression.Left is MemberExpression && ((MemberExpression)binaryExpression.Left).Member.Name == "ContractName")
         {
             IList<IService> services = resolver.Resolve((string)((ConstantExpression)binaryExpression.Right).Value, TimeOut, definition.Cardinality == ImportCardinality.ZeroOrOne ? 0 : 1, definition.Cardinality == ImportCardinality.ZeroOrMore ? int.MaxValue : 1);
             foreach (IService service in services)
                 resolver_ServiceFound(service);
         }
     }
     var exports = new List<TempTuple<ComposablePartDefinition, ExportDefinition>>();
     foreach (var part in this.Parts.ToArray())
     {
         foreach (var export in part.ExportDefinitions)
         {
             if (definition.Constraint.Compile().Invoke(export))
             {
                 exports.Add(new TempTuple<ComposablePartDefinition, ExportDefinition>(part, export));
             }
         }
     }
     return exports;
 }
        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            var contractName = definition.ContractName;

            if (contractName != SettingsConstants.SettingsContract)
                yield break;

            if (definition.Cardinality == ImportCardinality.ZeroOrMore)
                yield break;

            // TODO can't figure out how to get data injected into the Metadata collection
            //string settingsKey = definition.Metadata[SettingsConstants.SettingsMetadataKey] as string;

            LazyMemberInfo lazyMember = ReflectionModelServices.GetImportingMember(definition);
            MemberInfo member = lazyMember.GetAccessors().First();

            MethodInfo getterOrSetter = (MethodInfo)member;
            
            // HACK this is pretty evil
            PropertyInfo propInfo = getterOrSetter.DeclaringType.GetProperty(getterOrSetter.Name.Substring(4));

            ImportSettingAttribute settingsAttr = propInfo.GetCustomAttribute<ImportSettingAttribute>();

            if (settingsAttr == null)
                yield break;

            object value;
            if (!this._settingsProvider.TryGetValue(settingsAttr.SettingsKey, out value))
                yield break;

            yield return new Export(SettingsConstants.SettingsContract, () => value);
        }
        public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
        {
            if (definition == null) throw new ArgumentNullException("definition");
            if (exports == null) throw new ArgumentNullException("exports");

            InterceptedPart.SetImport(definition, exports);
        }
Exemple #6
0
        public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
        {
            Contract.Requires(definition != null);
            Contract.Requires(exports != null);

            throw new NotImplementedException();
        }
        /// <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 (!CompositionServices.IsReflectionImportDefinition(definition))
            {
                return Enumerable.Empty<Tuple<ComposablePartDefinition, ExportDefinition>>();
            }

            var returnedExports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();
            var importDefinitionType = CompositionServices.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 IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition, IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> exports)
        {
            var contractDef = (ContractBasedImportDefinition)definition;
            var returnedExports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();
            var importDefinitionType = TypeHelper.GetImportDefinitionType(definition);

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

            returnedExports.Concat(exports);

            if (this.manufacturedParts.Contains(importDefinitionType))
            {
                returnedExports.AddRange(this.catalog.GetExports(definition));
            }
            else if (TypeHelper.ShouldCreateClosedGenericPart(contractDef, importDefinitionType))
            {
                CreateGenericPart(importDefinitionType);
                returnedExports.AddRange(this.catalog.GetExports(definition));
            }

            return returnedExports;
        }
        public IDictionary<string, object> CacheImportDefinition(ComposablePartDefinition owner, ImportDefinition importDefinition)
        {
            ContractBasedImportDefinition contractBasedImport = importDefinition as ContractBasedImportDefinition;
            Assumes.NotNull(contractBasedImport);

            return CompositionCacheServices.WriteImportDefinition(owner, contractBasedImport);
        }
            protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
            {
                List<Export> exports = new List<Export>();

                ImportDefinition queryImport = TranslateImport(definition);
                if (queryImport == null)
                {
                    return exports;
                }

                // go through the catalogs and see if there's anything there of interest
                foreach (CompositionScopeDefinition childCatalog in this._scopeDefinition.Children)
                {
                    foreach (var partDefinitionAndExportDefinition in childCatalog.GetExportsFromPublicSurface(queryImport))
                    {
                        using (var container = this.CreateChildContainer(childCatalog))
                        {
                            // We create a nested AtomicComposition() because the container will be Disposed and 
                            // the RevertActions need to operate before we Dispose the child container
                            using (var ac = new AtomicComposition(atomicComposition))
                            {
                                var childCatalogExportProvider = container.CatalogExportProvider;
                                if (!childCatalogExportProvider.DetermineRejection(partDefinitionAndExportDefinition.Item1, ac))
                                {
                                    exports.Add(this.CreateScopeExport(childCatalog, partDefinitionAndExportDefinition.Item1, partDefinitionAndExportDefinition.Item2));
                                }
                            }
                        }
                    }
                }

                return exports;
            }
        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            if (definition == null) throw new ArgumentNullException("definition");
            if (SourceProvider == null) throw new InvalidOperationException("SourceProvider must be set.");

            var cbid = definition as ContractBasedImportDefinition;

            if (cbid == null || !cbid.RequiredTypeIdentity.StartsWith(PartCreatorContractPrefix))
                return EmptyExports;

            var importInfo = _importDefinitionCache.GetOrCreate(
                cbid,
                () => new ExportFactoryImport(cbid));

            var sourceExports = SourceProvider
                .GetExports(importInfo.ProductImport, atomicComposition);

            var result = sourceExports
                .Select(e => importInfo.CreateMatchingExport(e.Definition, SourceProvider))
                .ToArray();

            foreach (var e in sourceExports.OfType<IDisposable>())
                e.Dispose();

            return result;
        }
		protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
		{
			var serviceTypeName = definition.ContractName;
			if (serviceTypeName.IndexOf('.') == -1 ||
				serviceTypeName.StartsWith("System.") ||
				serviceTypeName.StartsWith("Clide."))
				return Enumerable.Empty<Export>();

			return serviceExports.GetOrAdd (serviceTypeName, contractName => {
				var serviceType = typeMap.GetOrAdd(contractName, typeName => MapType(typeName));
				if (serviceType == null)
					return Enumerable.Empty<Export>();

				// NOTE: if we can retrieve a valid instance of the service at least once, we 
				// assume we'll be able to retrieve it later on. Note also that we don't return 
				// the single retrieved instance from the export, but rather provide a function 
				// that does the GetService call every time, since we're caching the export but 
				// we don't know if the service can be safely cached.
				var service = services.GetService(serviceType);
				if (service == null)
					return Enumerable.Empty<Export>();

				return new Export[] { new Export(serviceTypeName, () => services.GetService(serviceType)) };
			});
		}
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="definition"></param>
 /// <param name="import"></param>
 /// <param name="exports"></param>
 /// <param name="composablePart"></param>
 public ImportableInfo(System.ComponentModel.Composition.Primitives.ImportDefinition definition, ProviderImportDefinition import, IEnumerable <Export> exports, ProviderComposablePart composablePart)
 {
     _definition     = definition;
     _import         = import;
     _exports        = exports;
     _composablePart = composablePart;
 }
Exemple #14
0
        private static ImportDefinition TranslateImport(ImportDefinition import, ComposablePartDefinition part)
        {
            ContractBasedImportDefinition contractBasedImport = import as ContractBasedImportDefinition;
            if (contractBasedImport == null)
            {
                return import;
            }

            int[] importParametersOrder = contractBasedImport.Metadata.GetValue<int[]>(CompositionConstants.GenericImportParametersOrderMetadataName);
            if (importParametersOrder == null)
            {
                return import;
            }

            int partArity = part.Metadata.GetValue<int>(CompositionConstants.GenericPartArityMetadataName);
            if (partArity == 0)
            {
                return import;
            }

            string contractName = GenericServices.GetGenericName(contractBasedImport.ContractName, importParametersOrder, partArity);
            string requiredTypeIdentity = GenericServices.GetGenericName(contractBasedImport.RequiredTypeIdentity, importParametersOrder, partArity);
            return new ContractBasedImportDefinition(
                         contractName,
                         requiredTypeIdentity,
                         contractBasedImport.RequiredMetadata,
                         contractBasedImport.Cardinality,
                         contractBasedImport.IsRecomposable,
                         false,
                         contractBasedImport.RequiredCreationPolicy,
                         contractBasedImport.Metadata);
        }
        /// <summary>
        /// Gets the available set of exports for the given import definition.
        /// </summary>
        /// <param name="definition">The defintion of the import.</param>
        /// <param name="atomicComposition">The atomic composition of the import.</param>
        /// <returns>The available set of exports for the given import definition.</returns>
        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            Throw.IfArgumentNull(definition, "definition");
            if (SourceProvider == null)
                Throw.InvalidOperation(
                    string.Format(
                        CultureInfo.CurrentUICulture,
                        Resources.Exceptions.PropertyCannotBeNull,
                        "Sourceprovider"));

            var contractDefinition = definition as ContractBasedImportDefinition;
            if (contractDefinition == null
                || !contractDefinition.RequiredTypeIdentity.StartsWith(PartFactoryContractPrefix))
                return EmptyExports;

            var info = _definitionCache.Fetch(contractDefinition, () => new PartFactoryImport(contractDefinition));

            var exports = SourceProvider.GetExports(info.ImportDefinition, atomicComposition);
            var result = exports
                .Select(e => info.CreateMatchingExport(e.Definition, SourceProvider))
                .ToArray();

            foreach (var export in exports.OfType<IDisposable>())
                export.Dispose();

            return result;
        }
Exemple #16
0
        /// <summary>
        /// Returns the available exports for the specified import definition.
        /// </summary>
        /// <param name="definition">The import definition.</param>
        /// <returns>The set of matching exports.</returns>
        public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            var definitions = _catalog.GetExports(definition);

            var list = HttpContext.Current.ModelList<ImportDescriptor>("MEF-Imports");

            var model = new ImportDescriptor
                            {
                                Cardinality = definition.Cardinality.ToString(),
                                ContractName = definition.ContractName,
                                Prerequisite = definition.IsPrerequisite,
                                Recomposable = definition.IsRecomposable
                            };

            foreach (var def in definitions)
            {
                var meta = def.Item2.Metadata.Keys
                    .Where(k => k != CreationPolicyTypeName)
                    .ToDictionary(key => key, key => def.Item2.Metadata[key].ToString());

                string policy = null;
                if (def.Item2.Metadata.ContainsKey(CreationPolicyTypeName))
                    policy = def.Item2.Metadata[CreationPolicyTypeName].ToString();

                var export = new ExportDescriptor { CreationPolicy = policy, DisplayName = def.Item1.ToString(), Metadata = meta };

                model.Exports.Add(export);
            }

            list.Add(model);

            return definitions;
        }
            public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
            {
                Requires.NotNull(definition, "definition");
                Requires.NotNullOrNullElements(exports, "exports");

                throw ExceptionBuilder.CreateImportDefinitionNotOnThisComposablePart("definition");
            }
Exemple #18
0
        protected override System.Collections.Generic.IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            var type = Type.GetType(definition.ContractName);
            Export e;
            var exports = base.GetExportsCore(definition, atomicComposition);

            return exports;
        }
Exemple #19
0
 public static CompositionError PreventedByExistingImport(ComposablePart part, ImportDefinition import)
 {
     return CompositionError.Create(
         CompositionErrorId.ImportEngine_PreventedByExistingImport,
         Strings.ImportEngine_PreventedByExistingImport,
         import.ToElement().DisplayName,
         part.ToElement().DisplayName);
 }
 public void TestSetUp()
 {
     ConcreteTypeHandler = new ConcreteTypeExportHandler();
     var typeCatalog = new TypeCatalog(typeof(CustomerProcessor));
     var orderProcessorContract = AttributedModelServices.GetContractName(typeof(CustomerProcessor));
     var orderProcessPartDefinition = typeCatalog.Parts.Single(p => p.ExportDefinitions.Any(d => d.ContractName == orderProcessorContract));
     RepositoryImportDefinition = orderProcessPartDefinition.ImportDefinitions.First();
 }
 public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports) {
     if (_composablePart.IsValueCreated ||
         _imports == null) {
         _composablePart.Value.SetImport(definition, exports);
     } else {
         _imports.Add(definition, exports);
     }
 }
        /// <summary>
        /// Gets the <see cref="Type"/> of the requested import.
        /// </summary>
        /// <param name="definition">The <see cref="ImportDefinition"/> instance.</param>
        /// <returns>A <see cref="Type"/> of the requested import.</returns>
        /// <remarks>Works only for reflection model import definitions.</remarks>
        public static Type GetImportDefinitionType(ImportDefinition definition)
        {
            var importDefinitionType = ReflectionModelServices.IsImportingParameter(definition)
                                           ? GetParameterType(definition)
                                           : GetMethodType(definition);

            return importDefinitionType;
        }
        /// <summary>
        /// Checks if the given <see cref="ImportDefinition"/> is based on reflection model.
        /// </summary>
        /// <param name="definition">The <see cref="ImportDefinition"/> instance.</param>
        /// <returns><c>True</c> if the given import definition is based on the
        /// reflection model. <c>False</c> otherwise.</returns>
        public static bool IsReflectionImportDefinition(ImportDefinition definition)
        {
            if (definition == null) throw new ArgumentNullException("definition");

            var name = definition.GetType().Name;
            return name == "ReflectionMemberImportDefinition" ||
                   name == "ReflectionParameterImportDefinition";
        }
Exemple #24
0
        public static Type GetParameterType(ImportDefinition definition)
        {
            var importingParameter = ReflectionModelServices.GetImportingParameter(definition);
            var parameterInfo = importingParameter.Value;
            var importDefinitionType = parameterInfo.ParameterType;

            return importDefinitionType;
        }
        protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {

            if (definition.ContractName.Equals(typeof(ILogger).FullName))
            {
                yield return new Export(definition.ContractName, () => new Logger() { Header = "Factory - " });
            }
        }
 protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
 {
     if (definition.ContractName == _textUndoHistoryRegistryContractName ||
         definition.ContractName == _basicUndoHistoryRegistryContractName)
     {
         yield return _export;
     }
 }
 public IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(
     ImportDefinition definition,
     IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> exports)
 {
     return from export in exports
            where Filter(export.Item1)
            select export;
 }
        /// <summary>
        /// Invokes TryGetExports, returning the output as a collection.
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="definition"></param>
        /// <param name="atomicComposition"></param>
        /// <returns></returns>
        public static IEnumerable<Export> TryGetExports(this ExportProvider provider, ImportDefinition definition, AtomicComposition atomicComposition)
        {
            Contract.Requires<ArgumentNullException>(provider != null);
            Contract.Requires<ArgumentNullException>(definition != null);

            IEnumerable<Export> exports;
            provider.TryGetExports(definition, atomicComposition, out exports);
            return exports;
        }
 /// <summary>
 /// Returns all exports that match the constraint defined by the specified definition.
 /// </summary>
 /// <param name="definition">The <see cref="T:System.ComponentModel.Composition.Primitives.ImportDefinition"/> that defines the conditions of the
 /// <see cref="T:System.ComponentModel.Composition.Primitives.Export"/> objects to return.</param>
 /// <param name="atomicComposition"></param>
 /// <returns></returns>
 /// <result>
 /// An <see cref="T:System.Collections.Generic.IEnumerable`1"/> of <see cref="T:System.ComponentModel.Composition.Primitives.Export"/> objects that match
 /// the conditions defined by <see cref="T:System.ComponentModel.Composition.Primitives.ImportDefinition"/>, if found; otherwise, an
 /// empty <see cref="T:System.Collections.Generic.IEnumerable`1"/>.
 ///   </result>
 protected override IEnumerable<Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
 {
     List<Export> exports = new List<Export>();
     if (_exportsDictionary.ContainsKey(definition.ContractName))
     {
         exports.Add(_exportsDictionary[definition.ContractName]);
     }
     return exports;
 }
        private object GetInstance(ImportDefinition definition, Type type, string configvalue)
        {
            if (typeof(ConfigurationItem).IsAssignableFrom(type) && type.IsGenericType)
            {
                return Activator.CreateInstance(type, definition.ContractName, this.Source);
            }

            return configvalue.ParseTo<object, string>(type);
        }
Exemple #31
0
        public override IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)
        {
            var exports = _catalog.GetExports(definition);

            if (!exports.Any() && TypeHelper.IsReflectionMemberImportDefinition(definition))
                exports = CreateDynamicExport(definition);

            return exports;
        }
Exemple #32
0
        public virtual IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            ThrowIfDisposed();

            Requires.NotNull(definition, nameof(definition));
            Contract.Ensures(Contract.Result <IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > >() != null);

            List <Tuple <ComposablePartDefinition, ExportDefinition> > exports = null;
            var candidateParts = GetCandidateParts(definition);

            if (candidateParts != null)
            {
                foreach (var part in candidateParts)
                {
                    Tuple <ComposablePartDefinition, ExportDefinition> singleMatch;
                    IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > multipleMatches;

                    if (part.TryGetExports(definition, out singleMatch, out multipleMatches))
                    {
                        exports = exports.FastAppendToListAllowNulls(singleMatch, multipleMatches);
                    }
                }
            }

            return(exports ?? _EmptyExportsList);
        }
        public virtual IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            this.ThrowIfDisposed();

            Requires.NotNull(definition, "definition");

            var exports = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();

            foreach (var part in this.Parts)
            {
                foreach (var export in part.ExportDefinitions)
                {
                    if (definition.IsConstraintSatisfiedBy(export))
                    {
                        exports.Add(new Tuple <ComposablePartDefinition, ExportDefinition>(part, export));
                    }
                }
            }
            return(exports);
        }
Exemple #34
0
        /// <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 virtual IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            ThrowIfDisposed();

            Requires.NotNull(definition, nameof(definition));

            List <Tuple <ComposablePartDefinition, ExportDefinition> >?exports = null;
            var candidateParts = GetCandidateParts(definition);

            if (candidateParts != null)
            {
                foreach (var part in candidateParts)
                {
                    if (part.TryGetExports(definition, out Tuple <ComposablePartDefinition, ExportDefinition>?singleMatch, out IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> >?multipleMatches))
                    {
                        exports = exports.FastAppendToListAllowNulls(singleMatch, multipleMatches);
                    }
                }
            }

            Debug.Assert(exports != null || _EmptyExportsList != null);
            return(exports ?? _EmptyExportsList);
        }
 public static ICompositionElement ToElement(this ImportDefinition definition)
 {
     return(ToElementCore(definition));
 }
Exemple #36
0
 /// <summary>
 ///     Sets the import described by the specified definition with the specified exports.
 /// </summary>
 /// <param name="definition">
 ///     One of the <see cref="ImportDefinition"/> objects from the
 ///     <see cref="ImportDefinitions"/> property describing the import to be set.
 /// </param>
 /// <param name="exports">
 ///     An <see cref="IEnumerable{T}"/> of <see cref="Export"/> objects of which
 ///     to set the import described by <paramref name="definition"/>.
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///     <paramref name="definition"/> is <see langword="null"/>.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name="exports"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="ArgumentException">
 ///     <paramref name="definition"/> did not originate from the <see cref="ImportDefinitions"/>
 ///     property on the <see cref="ComposablePart"/>.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name="exports"/> contains an element that is <see langword="null"/>.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name="exports"/> is empty and <see cref="ImportDefinition.Cardinality"/> is
 ///     <see cref="ImportCardinality.ExactlyOne"/>.
 ///     <para>
 ///         -or-
 ///     </para>
 ///     <paramref name="exports"/> contains more than one element and
 ///     <see cref="ImportDefinition.Cardinality"/> is <see cref="ImportCardinality.ZeroOrOne"/> or
 ///     <see cref="ImportCardinality.ExactlyOne"/>.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 ///     <see cref="Activate"/> has been previously called and
 ///     <see cref="ImportDefinition.IsRecomposable"/> is <see langword="false"/>.
 /// </exception>
 /// <exception cref="ObjectDisposedException">
 ///     The <see cref="ComposablePart"/> has been disposed of.
 /// </exception>
 /// <exception cref="ComposablePartException">
 ///     An error occurred setting the import described by the <see cref="ImportDefinition"/>.
 /// </exception>
 public abstract void SetImport(ImportDefinition definition, IEnumerable <Export> exports);
 public virtual new IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
 {
     return(default(IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> >));
 }
        /// <summary>
        /// Define o import.
        /// </summary>
        /// <param name="definition"></param>
        /// <param name="exports"></param>
        /// <exception cref="InvalidOperationException">The supplied import definition was of an unknown type.</exception>
        public override void SetImport(System.ComponentModel.Composition.Primitives.ImportDefinition definition, IEnumerable <Export> exports)
        {
            ProviderImportDefinition import = definition as ProviderImportDefinition;

            this.ImportedValues[definition] = new ImportableInfo(definition, import, exports, this);
        }
        public virtual IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            this.ThrowIfDisposed();

            Requires.NotNull(definition, "definition");
            Contract.Ensures(Contract.Result <IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > >() != null);

            List <Tuple <ComposablePartDefinition, ExportDefinition> > exports = null;
            var candidateParts = this.GetCandidateParts(definition);

            if (candidateParts != null)
            {
                foreach (var part in candidateParts)
                {
                    var partExports = part.GetExports(definition);
                    if (partExports != ComposablePartDefinition._EmptyExports)
                    {
                        exports = exports.FastAppendToListAllowNulls(partExports);
                    }
                }
            }

            return(exports ?? _EmptyExportsList);
        }
 internal virtual IEnumerable <ComposablePartDefinition> GetCandidateParts(ImportDefinition definition)
 {
     return(this);
 }
Exemple #41
0
 /// <summary>
 /// Retourne une collection de tous les exports qui correspondent aux conditions spécifiées dans l'<see cref="T:System.ComponentModel.Composition.Primitives.ImportDefinition"/>.
 /// </summary>
 /// <param name="definition">un objet définissant les conditions d'export</param>
 /// <param name="atomicComposition">La transaction de composition à utiliser.</param>
 /// <returns>
 /// Une collection des exports dans ce conteneur correspondant aux conditions de la définition.
 /// </returns>
 protected override IEnumerable <System.ComponentModel.Composition.Primitives.Export> GetExportsCore(System.ComponentModel.Composition.Primitives.ImportDefinition definition, AtomicComposition atomicComposition)
 {
     return(base.GetExportsCore(AdaptDefinition(definition), atomicComposition));
 }
Exemple #42
0
        internal virtual IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition)
        {
            List <Tuple <ComposablePartDefinition, ExportDefinition> > exports = null;

            foreach (var export in this.ExportDefinitions)
            {
                if (definition.IsConstraintSatisfiedBy(export))
                {
                    if (exports == null)
                    {
                        exports = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();
                    }
                    exports.Add(new Tuple <ComposablePartDefinition, ExportDefinition>(this, export));
                }
            }

            return(exports ?? _EmptyExports);
        }