当前位置: 首页>>代码示例>>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;未经允许,请勿转载。