public AddInComposablePartDefinition(AddInCatalog catalog, ComposablePartDefinition composablePartDefinition) { this._composablePartDefinition = composablePartDefinition; List<KeyValuePair<string, object>> injectedMetadata = new List<KeyValuePair<string, object>>(); injectedMetadata.Add(new KeyValuePair<string, object>(AddInCatalog.PackageIdMetadataName, catalog.PackageId)); injectedMetadata.Add(new KeyValuePair<string, object>(AddInCatalog.PackageVersionMetadataName, catalog.PackageVersion)); List<ExportDefinition> interceptedExports = new List<ExportDefinition>(); foreach (ExportDefinition export in composablePartDefinition.ExportDefinitions) { ICompositionElement compositionElement = export as ICompositionElement; if (compositionElement == null) throw new InvalidOperationException("ExportDefinition doesn't implement ICompositionElement"); Dictionary<string, object> metadata = injectedMetadata.Concat(export.Metadata) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); // TODO this will fail if export isn't a ReflectionMemberExportDefinition (Internal, so I can't check) LazyMemberInfo lazyMember = ReflectionModelServices.GetExportingMember(export); ExportDefinition interceptedExport = ReflectionModelServices.CreateExportDefinition(lazyMember, export.ContractName, new Lazy<IDictionary<string, object>>(() => metadata), compositionElement.Origin); interceptedExports.Add(interceptedExport); } this._exportDefinitions = interceptedExports.ToArray(); }
public AddInComposablePartDefinition(AddInCatalog catalog, ComposablePartDefinition composablePartDefinition) { this._composablePartDefinition = composablePartDefinition; List <KeyValuePair <string, object> > injectedMetadata = new List <KeyValuePair <string, object> >(); injectedMetadata.Add(new KeyValuePair <string, object>(AddInCatalog.PackageIdMetadataName, catalog.PackageId)); injectedMetadata.Add(new KeyValuePair <string, object>(AddInCatalog.PackageVersionMetadataName, catalog.PackageVersion)); List <ExportDefinition> interceptedExports = new List <ExportDefinition>(); foreach (ExportDefinition export in composablePartDefinition.ExportDefinitions) { ICompositionElement compositionElement = export as ICompositionElement; if (compositionElement == null) { throw new InvalidOperationException("ExportDefinition doesn't implement ICompositionElement"); } Dictionary <string, object> metadata = injectedMetadata.Concat(export.Metadata) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); // TODO this will fail if export isn't a ReflectionMemberExportDefinition (Internal, so I can't check) LazyMemberInfo lazyMember = ReflectionModelServices.GetExportingMember(export); ExportDefinition interceptedExport = ReflectionModelServices.CreateExportDefinition(lazyMember, export.ContractName, new Lazy <IDictionary <string, object> >(() => metadata), compositionElement.Origin); interceptedExports.Add(interceptedExport); } this._exportDefinitions = interceptedExports.ToArray(); }