當前位置: 首頁>>代碼示例>>C#>>正文


C# CompositionBatch.AddExport方法代碼示例

本文整理匯總了C#中System.ComponentModel.Composition.Hosting.CompositionBatch.AddExport方法的典型用法代碼示例。如果您正苦於以下問題:C# CompositionBatch.AddExport方法的具體用法?C# CompositionBatch.AddExport怎麽用?C# CompositionBatch.AddExport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ComponentModel.Composition.Hosting.CompositionBatch的用法示例。


在下文中一共展示了CompositionBatch.AddExport方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SatisfyImportsOnce

        public void SatisfyImportsOnce(ComposablePart part)
        {
            if (this.DoNothingOnSatisfyImportsOnce)
            {
                return;
            }

            CompositionBatch batch = new CompositionBatch();

            // We only want to include the standard exports and parts to compose in the first composition
            if (!this.alreadyComposed)
            {
                foreach (object instance in this.PartsToCompose)
                {
                    batch.AddPart(instance);
                }

                foreach (Export export in this.ExportsToCompose)
                {
                    batch.AddExport(export);
                }
            }

            if (part != null)
            {
                batch.AddPart(part);
            }

            this.container.Compose(batch);
            this.alreadyComposed = true;
        }
開發者ID:SonarSource-VisualStudio,項目名稱:sonarlint-visualstudio,代碼行數:31,代碼來源:ConfigurableCompositionService.cs

示例2: Configure

        public void Configure(ApplicationConfigurationBase applicationConfiguration)
        {
            if (IsConfigured)
                return;

            // Compose app container
            var batch = new CompositionBatch();
            foreach (var entry in _Entries)
            {
                var entryType = entry.GetType();
                var contractName = AttributedModelServices.GetContractName(entryType);
                var typeIdentity = AttributedModelServices.GetTypeIdentity(entryType);
                var metadata = new Dictionary<string, object> { { "ExportTypeIdentity", typeIdentity } };
                batch.AddExport(new Export(contractName, metadata, () => entry));
            }

            applicationConfiguration.CompositionContainer.Compose(batch);

            IsConfigured = true;
        }
開發者ID:PowerDMS,項目名稱:Owin.Scim,代碼行數:20,代碼來源:CompositionContainerRegistry.cs

示例3: DiscoverWork

        private IEnumerable<UnitOfWork> DiscoverWork(TemplateData templateData, XPathVariable[] parameters, Resource[] resources)
        {
            CustomXsltContext xpathContext = CreateCustomXsltContext(templateData.IgnoredVersionComponent);
            xpathContext.PushVariableScope(templateData.Document.Root, parameters);
            for (int i = 0; i < resources.Length; i++)
            {
                xpathContext.PushVariableScope(templateData.Document.Root, resources[i].Variables);

                if (EvalCondition(xpathContext, templateData.Document.Root, resources[i].ConditionExpression))
                {
                    string expandedSource = EvalValue(xpathContext, templateData.Document.Root, resources[i].Source);
                    string expandedOutput = EvalValue(xpathContext, templateData.Document.Root, resources[i].Output);

                    List<IResourceTransform> transforms = new List<IResourceTransform>();

                    foreach (var resourceTransform in resources[i].Transforms)
                    {
                        using (CompositionContainer localContainer = new CompositionContainer(this._container.Catalog))
                        {
                            string dirName = Path.GetDirectoryName(expandedSource);
                            CompositionBatch batch = new CompositionBatch();
                            var exportMetadata = new Dictionary<string, object>();

                            exportMetadata.Add(CompositionConstants.ExportTypeIdentityMetadataName,
                                               AttributedModelServices.GetTypeIdentity(typeof(IFileProvider)));

                            exportMetadata.Add(CompositionConstants.PartCreationPolicyMetadataName,
                                               CreationPolicy.Shared);

                            batch.AddExport(new Export(ContractNames.ResourceFileProvider,
                                                       exportMetadata,
                                                       () => new ScopedFileProvider(resources[i].FileProvider, dirName)));

                            // TODO export resourceTransform.Parameters into localContainer using CompositionBatch

                            localContainer.Compose(batch);

                            var requiredMetadata = new[]
                                                   {
                                                       new Tuple<string, object, IEqualityComparer>("Name",
                                                                                                    resourceTransform.Name,
                                                                                                    StringComparer.OrdinalIgnoreCase)
                                                   };

                            ImportDefinition importDefinition =
                                new MetadataContractBasedImportDefinition(
                                    typeof(IResourceTransform),
                                    null,
                                    requiredMetadata,
                                    ImportCardinality.ExactlyOne,
                                    false,
                                    true,
                                    CreationPolicy.NonShared);

                            Export transformExport = localContainer.GetExports(importDefinition).Single();

                            transforms.Add((IResourceTransform)transformExport.Value);
                        }
                    }

                    yield return
                        new ResourceDeployment(resources[i].FileProvider,
                                               expandedSource,
                                               expandedOutput, // TODO this needs a 'writable' file provider
                                               transforms.ToArray());
                }
                xpathContext.PopVariableScope();
            }
            xpathContext.PopVariableScope();

        }
開發者ID:LBiNetherlands,項目名稱:LBi.LostDoc,代碼行數:71,代碼來源:Template.cs

示例4: InAdditionToCatalogTest

        public void InAdditionToCatalogTest()
        {
            var container = ContainerFactory.CreateWithDefaultAttributedCatalog();
            
            IDictionary<string, object> multMetadata = new Dictionary<string, object>();
            multMetadata["Var1"]= "mult";
            multMetadata[CompositionConstants.ExportTypeIdentityMetadataName] = AttributedModelServices.GetTypeIdentity(typeof(Func<int, int, int>));
            var basicValue = ExportFactory.Create("Add", multMetadata, (() => (Func<int, int, int>)delegate(int a, int b) { return a * b; }));

            CompositionBatch batch = new CompositionBatch();
            batch.AddExport(basicValue);
            container.Compose(batch);

            var exports = container.GetExports<Func<int, int, int>, IExportableTest>("Add");

            Assert.AreEqual(3, exports.Count(), "There should be 3 entries for 'Add'");

            foreach (var export in exports)
            {
                if (export.Metadata.Var1 == "mult")
                {
                    Assert.AreEqual(2, export.Value(1, 2), "1 * 2 == 2");
                }
                else if (export.Metadata.Var1 == "add")
                {
                    Assert.AreEqual(3, export.Value(1, 2), "1 + 2 == 3");
                }
                else if (export.Metadata.Var1 == "sub")
                {
                    Assert.AreEqual(-1, export.Value(1, 2), "1 - 2 == -1");
                }
                else
                {
                    Assert.Fail("Unexpected value");
                }
            }
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:37,代碼來源:AdvancedValueComposition.cs


注:本文中的System.ComponentModel.Composition.Hosting.CompositionBatch.AddExport方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。