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


C# BuildItemGroup.AddExistingItem方法代码示例

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


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

示例1: Evaluate

        /// <summary>
        /// Evaluates the item and returns a virtual group containing any resulting items.
        /// This allows an item to be evaluated without it belonging to an item group.
        /// </summary>
        internal BuildItemGroup Evaluate(Expander expander, 
                                        string baseDirectory, 
                                        bool expandMetadata,
                                        ParserOptions parserOptions,
                                        EngineLoggingServices loggingServices, 
                                        BuildEventContext buildEventContext)
        {
            BuildItemGroup result = new BuildItemGroup();
            bool itemCondition = Utilities.EvaluateCondition(Condition,
                                                             ConditionAttribute,
                                                             expander,
                                                             parserOptions,
                                                             loggingServices,
                                                             buildEventContext);
            if (!itemCondition)
            {
                return result;
            }

            EvaluateAllItemMetadata(expander, parserOptions, loggingServices, buildEventContext);
            BuildItemGroup items = BuildItemGroup.ExpandItemIntoItems(baseDirectory, this, expander, expandMetadata);

            for (int i = 0; i < items.Count; i++)
            {
                BuildItem newItem = CreateClonedParentedItem(items[i], this);
                result.AddExistingItem(newItem);
            }

            return result;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:34,代码来源:BuildItem.cs

示例2: ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem

        public void ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem()
        {
            // Create some project state with an item with m=m1 and n=n1 
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            BuildItemGroup group0 = new BuildItemGroup();
            group0.AddExistingItem(item1);
            table1["i1"] = group0;

            Lookup lookup = LookupHelpers.CreateLookup(table1);

            lookup.EnterScope();

            // Make a modification to the item to be m=m2
            Dictionary<string, string> newMetadata = new Dictionary<string, string>();
            newMetadata.Add("m", "m2");
            BuildItemGroup group = new BuildItemGroup();
            group.AddItem(item1);
            lookup.ModifyItems(item1.Name, group, newMetadata);

            // Get the item (under the covers, it cloned it in order to apply the modification)
            BuildItemGroup group2 = lookup.GetItems(item1.Name);
            Assertion.AssertEquals(1, group2.Count);
            BuildItem item1b = group2[0];

            // Modify to m=m3
            Dictionary<string, string> newMetadata2 = new Dictionary<string, string>();
            newMetadata2.Add("m", "m3");
            BuildItemGroup group3 = new BuildItemGroup();
            group3.AddItem(item1b);
            lookup.ModifyItems(item1b.Name, group3, newMetadata2);

            // Modifications are visible
            BuildItemGroup group4 = lookup.GetItems(item1b.Name);
            Assertion.AssertEquals(1, group4.Count);
            Assertion.AssertEquals("m3", group4[0].GetMetadata("m"));

            // Leave scope
            lookup.LeaveScope();

            // Still visible
            BuildItemGroup group5 = lookup.GetItems(item1b.Name);
            Assertion.AssertEquals(1, group5.Count);
            Assertion.AssertEquals("m3", group5[0].GetMetadata("m"));

            // And the one in the project is changed
            Assertion.AssertEquals("m3", item1.GetMetadata("m"));
        }
开发者ID:nikson,项目名称:msbuild,代码行数:49,代码来源:Lookup_Tests.cs

示例3: RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem

        public void RemoveItemFromProjectPreviouslyModifiedAndGottenThroughGetItem()
        {
            // Create some project state with an item with m=m1 and n=n1 
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            BuildItemGroup group0 = new BuildItemGroup();
            group0.AddExistingItem(item1);
            table1["i1"] = group0;

            Lookup lookup = LookupHelpers.CreateLookup(table1);

            lookup.EnterScope();

            // Make a modification to the item to be m=m2
            Dictionary<string, string> newMetadata = new Dictionary<string, string>();
            newMetadata.Add("m", "m2");
            BuildItemGroup group = new BuildItemGroup();
            group.AddItem(item1);
            lookup.ModifyItems(item1.Name, group, newMetadata);

            // Get the item (under the covers, it cloned it in order to apply the modification)
            BuildItemGroup group2 = lookup.GetItems(item1.Name);
            Assertion.AssertEquals(1, group2.Count);
            BuildItem item1b = group2[0];

            // Remove the item
            lookup.RemoveItem(item1b);

            // There's now no items at all
            BuildItemGroup group3 = lookup.GetItems(item1.Name);
            Assertion.AssertEquals(0, group3.Count);

            // Leave scope
            lookup.LeaveScope();

            // And now none left in the project either
            Assertion.AssertEquals(0, ((BuildItemGroup)table1["i1"]).Count);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:39,代码来源:Lookup_Tests.cs

示例4: Backup1

        public void Backup1()
        {
            BuildItemGroup group = new BuildItemGroup(); // virtual group
            XmlElement element = CreatePersistedItemGroupElement();

            BuildItem item1 = CreatePersistedBuildItem(element, "i", "i1");
            BuildItem item2 = CreatePersistedBuildItem(element, "i", "i2");
            group.AddExistingItem(item1);
            group.AddExistingItem(item2);
            BuildItem item3 = group.AddNewItem("j", "j1"); // virtual
            Assertion.AssertEquals(3, group.Count);

            group.RemoveItemWithBackup(item3);
            group.RemoveItemWithBackup(item1);
            Assertion.AssertEquals(1, group.Count);

            group.RemoveAllIntermediateItems();
            Assertion.AssertEquals(2, group.Count);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:19,代码来源:BuildItemGroup_Tests.cs


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