/// <summary> /// Instancia do membro associado. /// </summary> public System.Reflection.MemberInfo GetMember() { if (_member == null) { if (_member == null) { if (_part != null && _part.ImportingConstructor != null) { _member = (System.Reflection.MemberInfo)_part.ImportingConstructor.GetConstructor(_catalog._assemblies); } else if (_part != null) { _member = _catalog.GetMemberInfo(_part.TypeName, _export.MemberName); } if (_member != null) { _catalog = null; _part = null; _export = null; } } } return(_member); }
private void DiscoverTypes(IEnumerable <ContractInfo> contracts) { lock (_lock) { if (_catalogCollection == null) { _catalogCollection = new AggregateCatalog(); } var exports = new List <Tuple <ContractInfo, Colosoft.Reflection.Composition.IExport> >(); foreach (var i in contracts) { if (i.Types.Count == 0) { var tuple = new Tuple <ContractInfo, Reflection.Composition.IExport>(i, ExportManager.GetExport(i.ContractType, i.ContractName, _uiContext)); if (tuple.Item2 != null) { exports.Add(tuple); } } else { var contractExports = ExportManager.GetExports(i.ContractType, i.ContractName, _uiContext); int contractCount = 0; foreach (var j in contractExports) { if (i.Types.Contains(j.Type, Colosoft.Reflection.TypeName.TypeNameEqualityComparer.Instance)) { contractCount++; var tuple = new Tuple <ContractInfo, Reflection.Composition.IExport>(i, j); exports.Add(tuple); } } } } if (exports.Count > 0) { var pkgParts = new List <Colosoft.Reflection.AssemblyPart>(); var partDescriptions = new List <PartDescription>(); foreach (var i in exports) { var assemblyPart = new Colosoft.Reflection.AssemblyPart(string.Format("{0}.dll", i.Item2.Type.AssemblyName.Name)); if (!pkgParts.Exists(f => StringComparer.InvariantCultureIgnoreCase.Equals(f.Source, assemblyPart.Source))) { pkgParts.Add(assemblyPart); } System.ComponentModel.Composition.CreationPolicy creationPolicy = System.ComponentModel.Composition.CreationPolicy.Any; switch (i.Item2.CreationPolicy) { case Reflection.Composition.CreationPolicy.NonShared: creationPolicy = System.ComponentModel.Composition.CreationPolicy.NonShared; break; case Reflection.Composition.CreationPolicy.Shared: creationPolicy = System.ComponentModel.Composition.CreationPolicy.Shared; break; } ImportingConstructorDescription importingConstructor = null; if (i.Item2.ImportingConstructor) { importingConstructor = new ImportingConstructorDescription(i.Item2.Type, null); } var partDescription = new PartDescription(i.Item2.Type, new ExportDescription[] { new ExportDescription { ContractTypeName = i.Item1.ContractType, ContractName = string.IsNullOrEmpty(i.Item2.ContractName) ? null : i.Item2.ContractName.Trim(), Metadata = i.Item2.Metadata } }, new ImportDescription[0], i.Item2.UseDispatcher, importingConstructor, creationPolicy); partDescriptions.Add(partDescription); } var catalog = new DefinitionCatalog(new DiscoverAssembliesContainer(this, _assemblyRepository, pkgParts.ToArray(), exports), partDescriptions); var addedDefinitions = catalog.Parts; using (AtomicComposition composition = new AtomicComposition()) { var args = new ComposablePartCatalogChangeEventArgs(addedDefinitions, Enumerable.Empty <ComposablePartDefinition>(), composition); this.OnChanging(args); _catalogCollection.Catalogs.Add(catalog); composition.Complete(); } ComposablePartCatalogChangeEventArgs e = new ComposablePartCatalogChangeEventArgs(addedDefinitions, Enumerable.Empty <ComposablePartDefinition>(), null); this.OnChanged(e); } } }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="catalog"></param> /// <param name="part"></param> /// <param name="export"></param> public ProviderExportDefinitionMemberGetter(DefinitionCatalog catalog, PartDescription part, ExportDescription export) { _catalog = catalog; _part = part; _export = export; }