当前位置: 首页>>代码示例>>C#>>正文


C# ItemDictionary.ImportItems方法代码示例

本文整理汇总了C#中ItemDictionary.ImportItems方法的典型用法代码示例。如果您正苦于以下问题:C# ItemDictionary.ImportItems方法的具体用法?C# ItemDictionary.ImportItems怎么用?C# ItemDictionary.ImportItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ItemDictionary的用法示例。


在下文中一共展示了ItemDictionary.ImportItems方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExpandAllIntoTaskItems3

        public void ExpandAllIntoTaskItems3()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();

            List<ProjectItemInstance> ig = new List<ProjectItemInstance>();
            ig.Add(new ProjectItemInstance(project, "Compile", "foo.cs", project.FullPath));
            ig.Add(new ProjectItemInstance(project, "Compile", "bar.cs", project.FullPath));

            List<ProjectItemInstance> ig2 = new List<ProjectItemInstance>();
            ig2.Add(new ProjectItemInstance(project, "Resource", "bing.resx", project.FullPath));

            ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>();
            itemsByType.ImportItems(ig);
            itemsByType.ImportItems(ig2);

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, itemsByType);

            IList<TaskItem> itemsOut = expander.ExpandIntoTaskItemsLeaveEscaped("foo;bar;@(compile);@(resource)", ExpanderOptions.ExpandPropertiesAndItems, MockElementLocation.Instance);

            ObjectModelHelpers.AssertItemsMatch(@"
                foo
                bar
                foo.cs
                bar.cs
                bing.resx
                ", GetTaskArrayFromItemList(itemsOut));
        }
开发者ID:akrisiun,项目名称:msbuild,代码行数:28,代码来源:Expander_Tests.cs

示例2: StringMetadataTable

        /// <summary>
        /// Creates a set of complicated item metadata and properties, and items to exercise
        /// the Expander class.  The data here contains escaped characters, metadata that
        /// references properties, properties that reference items, and other complex scenarios.
        /// </summary>
        /// <param name="pg"></param>
        /// <param name="primaryItemsByName"></param>
        /// <param name="secondaryItemsByName"></param>
        /// <param name="itemMetadata"></param>
        private void CreateComplexPropertiesItemsMetadata
            (
            out ReadOnlyLookup readOnlyLookup,
            out StringMetadataTable itemMetadata
            )
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            itemMetadataTable["Culture"] = "abc%253bdef;$(Gee_Aych_Ayee)";
            itemMetadataTable["Language"] = "english";
            itemMetadata = new StringMetadataTable(itemMetadataTable);

            PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
            pg.Set(ProjectPropertyInstance.Create("Gee_Aych_Ayee", "ghi"));
            pg.Set(ProjectPropertyInstance.Create("OutputPath", @"\jk ; l\mno%253bpqr\stu"));
            pg.Set(ProjectPropertyInstance.Create("TargetPath", "@(IntermediateAssembly->'%(RelativeDir)')"));

            List<ProjectItemInstance> intermediateAssemblyItemGroup = new List<ProjectItemInstance>();
            ProjectItemInstance i1 = new ProjectItemInstance(project, "IntermediateAssembly", @"subdir1\engine.dll", project.FullPath);
            intermediateAssemblyItemGroup.Add(i1);
            i1.SetMetadata("aaa", "111");
            ProjectItemInstance i2 = new ProjectItemInstance(project, "IntermediateAssembly", @"subdir2\tasks.dll", project.FullPath);
            intermediateAssemblyItemGroup.Add(i2);
            i2.SetMetadata("bbb", "222");

            List<ProjectItemInstance> contentItemGroup = new List<ProjectItemInstance>();
            ProjectItemInstance i3 = new ProjectItemInstance(project, "Content", "splash.bmp", project.FullPath);
            contentItemGroup.Add(i3);
            i3.SetMetadata("ccc", "333");

            List<ProjectItemInstance> resourceItemGroup = new List<ProjectItemInstance>();
            ProjectItemInstance i4 = new ProjectItemInstance(project, "Resource", "string$(p).resx", project.FullPath);
            resourceItemGroup.Add(i4);
            i4.SetMetadata("ddd", "444");
            ProjectItemInstance i5 = new ProjectItemInstance(project, "Resource", "dialogs%253b.resx", project.FullPath);
            resourceItemGroup.Add(i5);
            i5.SetMetadata("eee", "555");

            List<ProjectItemInstance> contentItemGroup2 = new List<ProjectItemInstance>();
            ProjectItemInstance i6 = new ProjectItemInstance(project, "Content", "about.bmp", project.FullPath);
            contentItemGroup2.Add(i6);
            i6.SetMetadata("fff", "666");

            ItemDictionary<ProjectItemInstance> secondaryItemsByName = new ItemDictionary<ProjectItemInstance>();
            secondaryItemsByName.ImportItems(resourceItemGroup);
            secondaryItemsByName.ImportItems(contentItemGroup2);

            Lookup lookup = new Lookup(secondaryItemsByName, pg, null);

            // Add primary items
            lookup.EnterScope("x");
            lookup.PopulateWithItems("IntermediateAssembly", intermediateAssemblyItemGroup);
            lookup.PopulateWithItems("Content", contentItemGroup);

            readOnlyLookup = new ReadOnlyLookup(lookup);
        }
开发者ID:akrisiun,项目名称:msbuild,代码行数:65,代码来源:Expander_Tests.cs

示例3: PropertyFunctionConsumingItemMetadata

        public void PropertyFunctionConsumingItemMetadata()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            PropertyDictionary<ProjectPropertyInstance> pg = new PropertyDictionary<ProjectPropertyInstance>();
            Dictionary<string, string> itemMetadataTable = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            itemMetadataTable["Compile.Identity"] = "fOo.Cs";
            StringMetadataTable itemMetadata = new StringMetadataTable(itemMetadataTable);

            List<ProjectItemInstance> ig = new List<ProjectItemInstance>();
            pg.Set(ProjectPropertyInstance.Create("SomePath", @"c:\some\path"));
            ig.Add(new ProjectItemInstance(project, "Compile", "fOo.Cs", project.FullPath));

            ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>();
            itemsByType.ImportItems(ig);

            Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, itemsByType, itemMetadata);

            string result = expander.ExpandIntoStringLeaveEscaped(@"$([System.IO.Path]::Combine($(SomePath),%(Compile.Identity)))", ExpanderOptions.ExpandAll, MockElementLocation.Instance);

            Assert.Equal(@"c:\some\path\fOo.Cs", result);
        }
开发者ID:akrisiun,项目名称:msbuild,代码行数:21,代码来源:Expander_Tests.cs

示例4: Regress_Mutation_DuplicateBatchingBucketsAreFoldedTogether

        public void Regress_Mutation_DuplicateBatchingBucketsAreFoldedTogether()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            List<string> parameters = new List<string>();
            parameters.Add("%(File.Culture)");

            ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>();

            List<ProjectItemInstance> items = new List<ProjectItemInstance>();
            items.Add(new ProjectItemInstance(project, "File", "a.foo", project.FullPath));
            items.Add(new ProjectItemInstance(project, "File", "b.foo", project.FullPath)); // Need at least two items for this test case to ensure multiple buckets might be possible
            itemsByType.ImportItems(items);

            PropertyDictionary<ProjectPropertyInstance> properties = new PropertyDictionary<ProjectPropertyInstance>();

            List<ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), null);

            // If duplicate buckes have been folded correctly, then there will be exactly one bucket here
            // containing both a.foo and b.foo.
            Assert.AreEqual(1, buckets.Count);
        }
开发者ID:EshG,项目名称:msbuild,代码行数:21,代码来源:BatchingEngine_Tests.cs

示例5: GetBuckets

        public void GetBuckets()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            List<string> parameters = new List<string>();
            parameters.Add("@(File);$(unittests)");
            parameters.Add("$(obj)\\%(Filename).ext");
            parameters.Add("@(File->'%(extension)')");  // attributes in transforms don't affect batching

            ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>();

            IList<ProjectItemInstance> items = new List<ProjectItemInstance>();
            items.Add(new ProjectItemInstance(project, "File", "a.foo", project.FullPath));
            items.Add(new ProjectItemInstance(project, "File", "b.foo", project.FullPath));
            items.Add(new ProjectItemInstance(project, "File", "c.foo", project.FullPath));
            items.Add(new ProjectItemInstance(project, "File", "d.foo", project.FullPath));
            items.Add(new ProjectItemInstance(project, "File", "e.foo", project.FullPath));
            itemsByType.ImportItems(items);

            items = new List<ProjectItemInstance>();
            items.Add(new ProjectItemInstance(project, "Doc", "a.doc", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Doc", "b.doc", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Doc", "c.doc", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Doc", "d.doc", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Doc", "e.doc", project.FullPath));
            itemsByType.ImportItems(items);

            PropertyDictionary<ProjectPropertyInstance> properties = new PropertyDictionary<ProjectPropertyInstance>();
            properties.Set(ProjectPropertyInstance.Create("UnitTests", "unittests.foo"));
            properties.Set(ProjectPropertyInstance.Create("OBJ", "obj"));

            List<ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), MockElementLocation.Instance);

            Assert.AreEqual(5, buckets.Count);

            foreach (ItemBucket bucket in buckets)
            {
                // non-batching data -- same for all buckets
                XmlAttribute tempXmlAttribute = (new XmlDocument()).CreateAttribute("attrib");
                tempXmlAttribute.Value = "'$(Obj)'=='obj'";

                Assert.IsTrue(ConditionEvaluator.EvaluateCondition(tempXmlAttribute.Value, ParserOptions.AllowAll, bucket.Expander, ExpanderOptions.ExpandAll, Directory.GetCurrentDirectory(), MockElementLocation.Instance, null, new BuildEventContext(1, 2, 3, 4)));
                Assert.AreEqual("a.doc;b.doc;c.doc;d.doc;e.doc", bucket.Expander.ExpandIntoStringAndUnescape("@(doc)", ExpanderOptions.ExpandItems, MockElementLocation.Instance));
                Assert.AreEqual("unittests.foo", bucket.Expander.ExpandIntoStringAndUnescape("$(bogus)$(UNITTESTS)", ExpanderOptions.ExpandPropertiesAndMetadata, MockElementLocation.Instance));
            }

            Assert.AreEqual("a.foo", buckets[0].Expander.ExpandIntoStringAndUnescape("@(File)", ExpanderOptions.ExpandItems, MockElementLocation.Instance));
            Assert.AreEqual(".foo", buckets[0].Expander.ExpandIntoStringAndUnescape("@(File->'%(Extension)')", ExpanderOptions.ExpandItems, MockElementLocation.Instance));
            Assert.AreEqual("obj\\a.ext", buckets[0].Expander.ExpandIntoStringAndUnescape("$(obj)\\%(Filename).ext", ExpanderOptions.ExpandPropertiesAndMetadata, MockElementLocation.Instance));

            // we weren't batching on this attribute, so it has no value
            Assert.AreEqual(String.Empty, buckets[0].Expander.ExpandIntoStringAndUnescape("%(Extension)", ExpanderOptions.ExpandAll, MockElementLocation.Instance));

            ProjectItemInstanceFactory factory = new ProjectItemInstanceFactory(project, "i");
            items = buckets[0].Expander.ExpandIntoItemsLeaveEscaped("@(file)", factory, ExpanderOptions.ExpandItems, MockElementLocation.Instance);
            Assert.IsNotNull(items);
            Assert.AreEqual(1, items.Count);

            int invalidProjectFileExceptions = 0;
            try
            {
                // This should throw because we don't allow item lists to be concatenated
                // with other strings.
                bool throwAway;
                items = buckets[0].Expander.ExpandSingleItemVectorExpressionIntoItems("@(file)$(unitests)", factory, ExpanderOptions.ExpandItems, false /* no nulls */, out throwAway, MockElementLocation.Instance);
            }
            catch (InvalidProjectFileException ex)
            {
                // check we don't lose error codes from IPFE's during build
                Assert.AreEqual(ex.ErrorCode, "MSB4012");
                invalidProjectFileExceptions++;
            }

            // We do allow separators in item vectors, this results in an item group with a single flattened item
            items = buckets[0].Expander.ExpandIntoItemsLeaveEscaped("@(file, ',')", factory, ExpanderOptions.ExpandItems, MockElementLocation.Instance);
            Assert.IsNotNull(items);
            Assert.AreEqual(1, items.Count);
            Assert.AreEqual("a.foo", items[0].EvaluatedInclude);

            Assert.AreEqual(1, invalidProjectFileExceptions);
        }
开发者ID:EshG,项目名称:msbuild,代码行数:80,代码来源:BatchingEngine_Tests.cs

示例6: InvalidUnqualifiedMetadataReference

        public void InvalidUnqualifiedMetadataReference()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            List<string> parameters = new List<string>();
            parameters.Add("@(File)");
            parameters.Add("%(Culture)");

            ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>();

            List<ProjectItemInstance> items = new List<ProjectItemInstance>();

            ProjectItemInstance a = new ProjectItemInstance(project, "File", "a.foo", project.FullPath);
            items.Add(a);
            ProjectItemInstance b = new ProjectItemInstance(project, "File", "b.foo", project.FullPath);
            items.Add(b);
            a.SetMetadata("Culture", "fr-fr");
            itemsByType.ImportItems(items);

            PropertyDictionary<ProjectPropertyInstance> properties = new PropertyDictionary<ProjectPropertyInstance>();

            // This is expected to throw because not all items contain a value for metadata "Culture".
            // Only a.foo has a Culture metadata.  b.foo does not.
            List<ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), MockElementLocation.Instance);
        }
开发者ID:EshG,项目名称:msbuild,代码行数:24,代码来源:BatchingEngine_Tests.cs

示例7: ValidUnqualifiedMetadataReference

        public void ValidUnqualifiedMetadataReference()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            List<string> parameters = new List<string>();
            parameters.Add("@(File)");
            parameters.Add("%(Culture)");

            ItemDictionary<ProjectItemInstance> itemsByType = new ItemDictionary<ProjectItemInstance>();

            List<ProjectItemInstance> items = new List<ProjectItemInstance>();

            ProjectItemInstance a = new ProjectItemInstance(project, "File", "a.foo", project.FullPath);
            ProjectItemInstance b = new ProjectItemInstance(project, "File", "b.foo", project.FullPath);
            a.SetMetadata("Culture", "fr-fr");
            b.SetMetadata("Culture", "en-en");
            items.Add(a);
            items.Add(b);
            itemsByType.ImportItems(items);

            PropertyDictionary<ProjectPropertyInstance> properties = new PropertyDictionary<ProjectPropertyInstance>();

            List<ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), null);
            Assert.AreEqual(2, buckets.Count);
        }
开发者ID:EshG,项目名称:msbuild,代码行数:24,代码来源:BatchingEngine_Tests.cs

示例8: GenerateLookup

        private static Lookup GenerateLookup(ProjectInstance project, PropertyDictionary<ProjectPropertyInstance> properties)
        {
            List<ProjectItemInstance> items = new List<ProjectItemInstance>();
            ProjectItemInstance item1 = new ProjectItemInstance(project, "i0", "a1", project.FullPath);
            ProjectItemInstance item2 = new ProjectItemInstance(project, "i0", "a2", project.FullPath);
            ProjectItemInstance item3 = new ProjectItemInstance(project, "i0", "a3", project.FullPath);
            ProjectItemInstance item4 = new ProjectItemInstance(project, "i0", "a4", project.FullPath);
            item1.SetMetadata("m", "m1");
            item1.SetMetadata("n", "n1");
            item2.SetMetadata("m", "m2");
            item2.SetMetadata("n", "n2");
            item3.SetMetadata("m", "m2");
            item3.SetMetadata("n", "n2");
            item4.SetMetadata("m", "m3");
            item4.SetMetadata("n", "n3");
            items.Add(item1);
            items.Add(item2);
            items.Add(item3);
            items.Add(item4);
            ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();
            itemsByName.ImportItems(items);

            Lookup lookup = LookupHelpers.CreateLookup(properties, itemsByName);

            return lookup;
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:26,代码来源:IntrinsicTask_Tests.cs

示例9: MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems

        public void MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems()
        {
            Console.WriteLine("MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems");
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            string inputs = "@(Items);@(MoreItems)";
            string outputs = "@(Items->'%(Filename).dll');@(MoreItems->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[]
                                             {
                                                 new FileWriteInfo("a.cs", _yesterday),
                                                 new FileWriteInfo("a.txt", _yesterday),
                                                 new FileWriteInfo("a.dll", _today),
                                                 new FileWriteInfo("a.xml", _today),
                                                 new FileWriteInfo("b.cs", _yesterday),
                                                 new FileWriteInfo("b.txt", _yesterday),
                                                 new FileWriteInfo("b.dll", _twoDaysAgo),
                                                 new FileWriteInfo("b.xml", _today),
                                                 new FileWriteInfo("c.cs", _yesterday),
                                                 new FileWriteInfo("c.txt", _yesterday),
                                                 new FileWriteInfo("c.dll", _today),
                                                 new FileWriteInfo("c.xml", _today)
                                             };

            List<ProjectItemInstance> items = new List<ProjectItemInstance>();
            items.Add(new ProjectItemInstance(project, "Items", "a.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "b.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "c.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "a.txt", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "b.txt", project.FullPath));
            items.Add(new ProjectItemInstance(project, "MoreItems", "c.txt", project.FullPath));

            ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();
            itemsByName.ImportItems(items);

            ItemDictionary<ProjectItemInstance> changedTargetInputs = new ItemDictionary<ProjectItemInstance>();
            ItemDictionary<ProjectItemInstance> upToDateTargetInputs = new ItemDictionary<ProjectItemInstance>();
            DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs, out changedTargetInputs, out upToDateTargetInputs);

            foreach (ProjectItemInstance itemInstance in changedTargetInputs)
            {
                Console.WriteLine("Changed: {0}:{1}", itemInstance.ItemType, itemInstance.EvaluatedInclude);
            }

            Assert.Equal(DependencyAnalysisResult.IncrementalBuild, result); // "Should only build partially."

            // Even though they were all up to date, we still expect to see an empty marker
            // so that lookups can correctly *not* find items of that type
            Assert.True(changedTargetInputs.HasEmptyMarker("MoreItems"));
        }
开发者ID:nikson,项目名称:msbuild,代码行数:49,代码来源:TargetUpToDateChecker_Tests.cs

示例10: InputItemThatCorrelatesWithMultipleTransformOutputItems

        public void InputItemThatCorrelatesWithMultipleTransformOutputItems()
        {
            ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance();
            string inputs = "@(Items)";
            string outputs = "@(Items->'%(Filename).dll');@(Items->'%(Filename).xml')";

            FileWriteInfo[] filesToAnalyze = new FileWriteInfo[]
                                             {
                                                 new FileWriteInfo("a.cs", _yesterday),
                                                 new FileWriteInfo("a.dll", _today),
                                                 new FileWriteInfo("a.xml", _today),
                                                 new FileWriteInfo("b.cs", _yesterday),
                                                 new FileWriteInfo("b.dll", _twoDaysAgo),
                                                 new FileWriteInfo("b.xml", _today),
                                                 new FileWriteInfo("c.cs", _yesterday),
                                                 new FileWriteInfo("c.dll", _today),
                                                 new FileWriteInfo("c.xml", _today)
                                             };

            List<ProjectItemInstance> items = new List<ProjectItemInstance>();
            items.Add(new ProjectItemInstance(project, "Items", "a.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "b.cs", project.FullPath));
            items.Add(new ProjectItemInstance(project, "Items", "c.cs", project.FullPath));

            ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();
            itemsByName.ImportItems(items);

            DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs);

            Assert.Equal(DependencyAnalysisResult.IncrementalBuild, result); // "Should only build partially."
        }
开发者ID:nikson,项目名称:msbuild,代码行数:31,代码来源:TargetUpToDateChecker_Tests.cs


注:本文中的ItemDictionary.ImportItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。