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


C# BuildItemGroup.AddItem方法代码示例

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


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

示例1: ExpandAllIntoTaskItems3

        public void ExpandAllIntoTaskItems3()
        {
            BuildPropertyGroup pg = new BuildPropertyGroup();

            BuildItemGroup ig = new BuildItemGroup();
            ig.AddItem(new BuildItem("Compile", "foo.cs"));
            ig.AddItem(new BuildItem("Compile", "bar.cs"));

            BuildItemGroup ig2 = new BuildItemGroup();
            ig2.AddItem(new BuildItem("Resource", "bing.resx"));

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemsByType["Compile"] = ig;
            itemsByType["Resource"] = ig2;

            Expander expander = new Expander(pg, itemsByType);

            List<TaskItem> itemsOut = expander.ExpandAllIntoTaskItems("foo;bar;@(compile);@(resource)", null);

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

示例2: BasicProxying

        public void BasicProxying()
        {          
            BuildItemGroup ig = new BuildItemGroup();
            BuildItem i1 = new BuildItem("name1", "value1");
            i1.SetMetadata("myMetaName", "myMetaValue");
            BuildItem i2 = new BuildItem("name2", "value2");
            ig.AddItem(i1);
            ig.AddItem(i2);

            BuildItemGroupProxy proxy = new BuildItemGroupProxy(ig);

            // Gather everything into our own table
            Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);
            foreach (DictionaryEntry item in proxy)
            {
                list.Add(item.Key, item.Value);
            }

            // Check we got all the items
            Assertion.AssertEquals(2, list.Count);
            Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
            Assertion.AssertEquals("value2", ((TaskItem)list["name2"]).ItemSpec);

            // Check they have all their metadata
            int builtInMetadata = FileUtilities.ItemSpecModifiers.All.Length;
            Assertion.AssertEquals(1 + builtInMetadata, ((TaskItem)list["name1"]).MetadataCount);
            Assertion.AssertEquals(0 + builtInMetadata, ((TaskItem)list["name2"]).MetadataCount);
            Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));
        }
开发者ID:nikson,项目名称:msbuild,代码行数:29,代码来源:BuildItemGroupProxy_Tests.cs

示例3: CantModifyThroughEnumerator

        public void CantModifyThroughEnumerator()
        {
            BuildItemGroup ig = new BuildItemGroup();
            BuildItem i1 = new BuildItem("name1", "value1");
            i1.SetMetadata("myMetaName", "myMetaValue");
            ig.AddItem(i1);

            BuildItemGroupProxy proxy = new BuildItemGroupProxy(ig);

            Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);
            foreach (DictionaryEntry item in proxy)
            {
                list.Add(item.Key, item.Value);
            }

            // Change the item
            Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
            ((TaskItem)list["name1"]).ItemSpec = "newItemSpec";
            ((TaskItem)list["name1"]).SetMetadata("newMetadata", "newMetadataValue");

            // We did change our copy
            Assertion.AssertEquals("newItemSpec", ((TaskItem)list["name1"]).ItemSpec);
            Assertion.AssertEquals("newMetadataValue", ((TaskItem)list["name1"]).GetMetadata("newMetadata"));
            Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));

            // But get the item again
            list = new Hashtable(StringComparer.OrdinalIgnoreCase);
            foreach (DictionaryEntry item in proxy)
            {
                list.Add(item.Key, item.Value);
            }

            // Item value and metadata hasn't changed
            Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
            Assertion.AssertEquals("", ((TaskItem)list["name1"]).GetMetadata("newMetadata"));
            Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));
        }
开发者ID:nikson,项目名称:msbuild,代码行数:37,代码来源:BuildItemGroupProxy_Tests.cs

示例4: ModifyItemThatWasAddedInSameScope

        public void ModifyItemThatWasAddedInSameScope()
        {
            Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            Lookup lookup = LookupHelpers.CreateLookup(table1);

            lookup.EnterScope();

            // Add an item with m=m1
            BuildItem item1 = new BuildItem("i1", "a2");
            item1.SetMetadata("m", "m1");
            lookup.AddNewItem(item1);

            // Change 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);

            // Now it has m=m2
            group = lookup.GetItems("i1");
            Assertion.AssertEquals(1, group.Count);
            Assertion.AssertEquals("m2", group[0].GetMetadata("m"));

            // But the original item hasn't changed yet
            Assertion.AssertEquals("m1", item1.GetMetadata("m"));

            lookup.LeaveScope();

            // It still has m=m2
            group = lookup.GetItems("i1");
            Assertion.AssertEquals(1, group.Count);
            Assertion.AssertEquals("m2", group[0].GetMetadata("m"));

            // But now the original item has changed as well
            Assertion.AssertEquals("m2", item1.GetMetadata("m"));
        }
开发者ID:nikson,项目名称:msbuild,代码行数:37,代码来源:Lookup_Tests.cs

示例5: EvaluateAVarietyOfExpressions

        /// <summary>
        /// A whole bunch of conditionals, that should be true, false, or error 
        /// (many coincidentally like existing QA tests) to give breadth coverage.
        /// Please add more cases as they arise.
        /// </summary>
        /// <owner>danmose</owner>
        private void EvaluateAVarietyOfExpressions()
        {
            string[] files = { "a", "a;b", "a'b", ";", "'" };

            try
            {
                foreach (string file in files)
                {
                    using (StreamWriter sw = File.CreateText(file)) { ; }
                }

                Parser p = new Parser();
                GenericExpressionNode tree;

                BuildItemGroup itemGroupU = new BuildItemGroup();
                BuildItemGroup itemGroupV = new BuildItemGroup();
                BuildItemGroup itemGroupW = new BuildItemGroup();
                BuildItemGroup itemGroupX = new BuildItemGroup();
                BuildItemGroup itemGroupY = new BuildItemGroup();
                BuildItemGroup itemGroupZ = new BuildItemGroup();
                itemGroupU.AddItem(new BuildItem("u", "a'b;c"));
                itemGroupV.AddItem(new BuildItem("w", "a"));
                itemGroupW.AddItem(new BuildItem("w", "1"));
                itemGroupX.AddItem(new BuildItem("x", "true"));
                itemGroupY.AddItem(new BuildItem("y", "xxx"));
                itemGroupZ.AddItem(new BuildItem("z", "xxx"));
                itemGroupZ.AddItem(new BuildItem("z", "yyy"));
                Hashtable itemBag = new Hashtable(StringComparer.OrdinalIgnoreCase);
                itemBag["u"] = itemGroupU;
                itemBag["v"] = itemGroupV;
                itemBag["w"] = itemGroupW;
                itemBag["x"] = itemGroupX;
                itemBag["y"] = itemGroupY;
                itemBag["z"] = itemGroupZ;

                BuildPropertyGroup propertyBag = new BuildPropertyGroup();
                propertyBag.SetProperty("a", "no");
                propertyBag.SetProperty("b", "true");
                propertyBag.SetProperty("c", "1");
                propertyBag.SetProperty("d", "xxx");
                propertyBag.SetProperty("e", "xxx");
                propertyBag.SetProperty("and", "and");
                propertyBag.SetProperty("a_semi_b", "a;b");
                propertyBag.SetProperty("a_apos_b", "a'b");
                propertyBag.SetProperty("foo_apos_foo", "foo'foo");
                propertyBag.SetProperty("a_escapedsemi_b", "a%3bb");
                propertyBag.SetProperty("a_escapedapos_b", "a%27b");
                propertyBag.SetProperty("has_trailing_slash", @"foo\");

                Dictionary<string, string> itemMetadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
                itemMetadata["Culture"] = "french";

                Expander expander = new Expander(new ReadOnlyLookup(itemBag, propertyBag), itemMetadata);

                string[] trueTests = {
                    "true or (SHOULDNOTEVALTHIS)", // short circuit
                    "(true and false) or true",
                    "false or true or false",
                    "(true) and (true)",
                    "false or !false",
                    "($(a) or true)",
                    "('$(c)'==1 and (!false))",
                    "@(z -> '%(filename).z', '$')=='xxx.z$yyy.z'",
                    "false or (false or (false or (false or (false or (true)))))",
                    "!(true and false)",
                    "$(and)=='and'",
                    "0x1==1.0",
                    "0xa==10",
                    "0<0.1",
                    "+4>-4",
                    "'-$(c)'==-1",
                    "$(a)==faLse",
                    "$(a)==oFF",
                    "$(a)==no",
                    "$(a)!=true",
                    "$(b)== True",
                    "$(b)==on",
                    "$(b)==yes",
                    "$(b)!=1",
                    "$(c)==1",
                    "$(d)=='xxx'",
                    "$(d)==$(e)",
                    "$(d)=='$(e)'",
                    "@(y)==$(d)",
                    "'@(z)'=='xxx;yyy'",
                    "$(a)==$(a)",
                    "'1'=='1'",
                    "'1'==1",
                    "1\n==1",
                    "1\t==\t\r\n1",
                    "123=='0123.0'",
                    "123==123",
                    "123==0123",
                    "123==0123.0",
//.........这里部分代码省略.........
开发者ID:nikson,项目名称:msbuild,代码行数:101,代码来源:ExpressionTree_Tests.cs

示例6: ToBuildItemGroup

		static BuildItemGroup ToBuildItemGroup (string name, string items, bool split)
		{
			BuildItemGroup big = new BuildItemGroup ();
			if (split) {
				string [] splitItems = items.Split (';');
				foreach (string item in splitItems)
					big.AddItem (name, new TaskItem (item));
			} else {
				big.AddItem (name, new TaskItem (items));
			}

			return big;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:13,代码来源:ChangeType.cs

示例7: RemoveItemsByName

        /// <summary>
        /// Removes all Items of a given typoe from the collection.
        /// Recurses into Chooses in the collection removing Items as well.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <owner>DavidLe</owner>
        /// <param name="itemName"></param>
        internal void RemoveItemsByName(string itemName)
        {
            BuildItemGroup itemsToRemove = new BuildItemGroup();

            foreach (BuildItemGroup itemGroup in this.ItemGroupsAll)
            {
                // Now loop through the Items in the BuildItemGroup, and keep track of the
                // ones that are of the requested item type.
                foreach (BuildItem item in itemGroup)
                {
                    if ((0 == String.Compare(item.Name, itemName, StringComparison.OrdinalIgnoreCase)) &&
                            !item.IsImported
                        )
                    {
                        // We're not allowed to remove an item from a collection while
                        // the collection is being enumerated.  So we have to track it
                        // in a separate list.
                        itemsToRemove.AddItem(item);
                    }
                }
            }
            foreach (BuildItem itemToRemove in itemsToRemove)
            {
                itemToRemove.ParentPersistedItemGroup.ParentProject.RemoveItem(itemToRemove);
            }
        }
开发者ID:nikson,项目名称:msbuild,代码行数:34,代码来源:GroupingCollection.cs

示例8: 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

示例9: AddItem1

        public void AddItem1()
        {
            XmlElement ig = CreatePersistedItemGroupElement();
            BuildItemGroup group = new BuildItemGroup(ig, false, new Project());

            BuildItem item = CreatePersistedBuildItem(ig, "i", "i3");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 2); // should be last

            item = CreatePersistedBuildItem(ig, "h", "h1");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 3); // should be last, because there were no h's.

            item = CreatePersistedBuildItem(ig, "h", "h0");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 3);// should be 2nd last

            item = CreatePersistedBuildItem(ig, "i", "i2");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 1); // should be 2nd      

            item = CreatePersistedBuildItem(ig, "i", "i0");
            group.AddItem(item);
            VerifyPersistedItemPosition(group, item, 0); // should be first              
        }
开发者ID:nikson,项目名称:msbuild,代码行数:25,代码来源:BuildItemGroup_Tests.cs

示例10: ShallowCloneOfVirtualItemGroup

        public void ShallowCloneOfVirtualItemGroup()
        {
            BuildItemGroup group = new BuildItemGroup();
            group.AddNewItem("i", "i1");
            BuildItem i2 = new BuildItem("i", "i2");
            group.AddItem(i2);

            BuildItemGroup group2 = group.Clone(false /*shallow*/);

            Assertion.AssertEquals(2, group2.Count);
            Assertion.AssertEquals("i1", group2[0].FinalItemSpec);
            Assertion.Assert(i2.Equals(group2[1]));
        }
开发者ID:nikson,项目名称:msbuild,代码行数:13,代码来源:BuildItemGroup_Tests.cs

示例11: ConditionedPropertyUpdateTests

        public void ConditionedPropertyUpdateTests()
        {
            Parser p = new Parser();
            BuildPropertyGroup propertyBag = new BuildPropertyGroup();
            Hashtable conditionedProperties = new Hashtable(StringComparer.OrdinalIgnoreCase);

            BuildItemGroup myNewItemGroup = new BuildItemGroup();
            myNewItemGroup.AddItem(new BuildItem("Compile", "foo.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "bar.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "baz.cs"));
            Hashtable itemBag = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemBag["Compile"] = myNewItemGroup;

            Expander expander = new Expander(LookupHelpers.CreateLookup(itemBag).ReadOnlyLookup);
            ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, conditionedProperties, string.Empty);

            StringCollection sc;
            AssertParseEvaluate(p, "'0' == '1'", state, false);
            Assertion.Assert(conditionedProperties.Count == 0);

            AssertParseEvaluate(p, "$(foo) == foo", state, false);
            Assertion.Assert(conditionedProperties.Count == 1);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 1);

            AssertParseEvaluate(p, "'$(foo)' != 'bar'", state, true);
            Assertion.Assert(conditionedProperties.Count == 1);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 2);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab22dev|debug|x86'", state, false);
            Assertion.Assert(conditionedProperties.Count == 4);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["branch"];
            Assertion.Assert(sc.Count == 1);
            sc = (StringCollection)conditionedProperties["build"];
            Assertion.Assert(sc.Count == 1);
            sc = (StringCollection)conditionedProperties["platform"];
            Assertion.Assert(sc.Count == 1);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab21|debug|x86'", state, false);
            Assertion.Assert(conditionedProperties.Count == 4);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["branch"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["build"];
            Assertion.Assert(sc.Count == 1);
            sc = (StringCollection)conditionedProperties["platform"];
            Assertion.Assert(sc.Count == 1);

            AssertParseEvaluate(p, "'$(branch)|$(build)|$(platform)' == 'lab23|retail|ia64'", state, false);
            Assertion.Assert(conditionedProperties.Count == 4);
            sc = (StringCollection)conditionedProperties["foo"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["branch"];
            Assertion.Assert(sc.Count == 3);
            sc = (StringCollection)conditionedProperties["build"];
            Assertion.Assert(sc.Count == 2);
            sc = (StringCollection)conditionedProperties["platform"];
            Assertion.Assert(sc.Count == 2);
            DumpHashtable(conditionedProperties);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:64,代码来源:ExpressionTree_Tests.cs

示例12: OldSyntaxTests

        public void OldSyntaxTests()
        {
            Parser p = new Parser();
            BuildPropertyGroup propertyBag = new BuildPropertyGroup();
            Hashtable conditionedProperties = null;

            BuildItemGroup myNewItemGroup = new BuildItemGroup();
            myNewItemGroup.AddItem(new BuildItem("Compile", "foo.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "bar.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "baz.cs"));
            Hashtable itemBag = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemBag["COMPILE"] = myNewItemGroup;

            propertyBag = new BuildPropertyGroup();
            propertyBag.SetProperty("foo", "true");
            propertyBag.SetProperty("bar", "yes");
            propertyBag.SetProperty("one", "1");
            propertyBag.SetProperty("onepointzero", "1.0");
            propertyBag.SetProperty("two", "2");
            propertyBag.SetProperty("simple", "simplestring");
            propertyBag.SetProperty("complex", "This is a complex string");
            propertyBag.SetProperty("c1", "Another (complex) one.");
            propertyBag.SetProperty("c2", "Another (complex) one.");

            Expander expander = new Expander(propertyBag, itemBag);
            ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, conditionedProperties, string.Empty);

            AssertParseEvaluate(p, "(($(foo) != 'two' and $(bar)) and 5 >= 1) or $(one) == 1", state, true);}
开发者ID:nikson,项目名称:msbuild,代码行数:28,代码来源:ExpressionTree_Tests.cs

示例13: StringExpansionTests

        public void StringExpansionTests()
        {
            Parser p = new Parser();
            BuildPropertyGroup propertyBag = new BuildPropertyGroup();
            Hashtable conditionedProperties = null;

            BuildItemGroup myNewItemGroup = new BuildItemGroup();
            myNewItemGroup.AddItem(new BuildItem("Compile", "foo.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "bar.cs"));
            myNewItemGroup.AddItem(new BuildItem("Compile", "baz.cs"));
            Hashtable itemBag = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemBag["COMPILE"] = myNewItemGroup;

            propertyBag = new BuildPropertyGroup();
            propertyBag.SetProperty("foo", "true");
            propertyBag.SetProperty("bar", "yes");
            propertyBag.SetProperty("one", "1");
            propertyBag.SetProperty("onepointzero", "1.0");
            propertyBag.SetProperty("two", "2");
            propertyBag.SetProperty("simple", "simplestring");
            propertyBag.SetProperty("complex", "This is a complex string");
            propertyBag.SetProperty("c1", "Another (complex) one.");
            propertyBag.SetProperty("c2", "Another (complex) one.");
            propertyBag.SetProperty("TestQuote", "Contains'Quote'");
            propertyBag.SetProperty("AnotherTestQuote", "Here's Johnny!");
            propertyBag.SetProperty("Atsign", "Test the @ replacement");

            Expander expander = new Expander(propertyBag, itemBag);
            ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, conditionedProperties, string.Empty);

            AssertParseEvaluate(p, "'simplestring: true foo.cs;bar.cs;baz.cs' == '$(simple): $(foo) @(compile)'", state, true);
            AssertParseEvaluate(p, "'$(c1) $(c2)' == 'Another (complex) one. Another (complex) one.'", state, true);
            AssertParseEvaluate(p, "'CONTAINS%27QUOTE%27' == '$(TestQuote)'", state, true);
            AssertParseEvaluate(p, "'Here%27s Johnny!' == '$(AnotherTestQuote)'", state, true);
            AssertParseEvaluate(p, "'Test the %40 replacement' == $(Atsign)", state, true);}
开发者ID:nikson,项目名称:msbuild,代码行数:35,代码来源:ExpressionTree_Tests.cs

示例14: ItemListTests

        public void ItemListTests()
        {
            Parser p = new Parser();
            Hashtable conditionedProperties = null;

            BuildItemGroup myCompileItemGroup = new BuildItemGroup();
            myCompileItemGroup.AddItem(new BuildItem("Compile", "foo.cs"));
            myCompileItemGroup.AddItem(new BuildItem("Compile", "bar.cs"));
            myCompileItemGroup.AddItem(new BuildItem("Compile", "baz.cs"));

            BuildItemGroup myBooleanItemGroup = new BuildItemGroup();
            myBooleanItemGroup.AddItem(new BuildItem("Boolean", "true"));

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
            itemsByType["Compile"] = myCompileItemGroup;
            itemsByType["Boolean"] = myBooleanItemGroup;

            Expander expander = new Expander(LookupHelpers.CreateLookup(itemsByType).ReadOnlyLookup);
            ConditionEvaluationState state = new ConditionEvaluationState(DummyAttribute, expander, conditionedProperties, string.Empty);

            AssertParseEvaluate(p, "@(Compile) == 'foo.cs;bar.cs;baz.cs'", state, true);
            AssertParseEvaluate(p, "@(Compile,' ') == 'foo.cs bar.cs baz.cs'", state, true);
            AssertParseEvaluate(p, "@(Compile,'') == 'foo.csbar.csbaz.cs'", state, true);
            AssertParseEvaluate(p, "@(Compile->'%(Filename)') == 'foo;bar;baz'", state, true);
            AssertParseEvaluate(p, "@(Compile -> 'temp\\%(Filename).xml', ' ') == 'temp\\foo.xml temp\\bar.xml temp\\baz.xml'", state, true);
            AssertParseEvaluate(p, "@(Compile->'', '') == ''", state, true);
            AssertParseEvaluate(p, "@(Compile->'') == ';;'", state, true);
            AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)', '') == ''", state, true);
            AssertParseEvaluate(p, "@(Compile->'%(Nonexistent)') == ';;'", state, true);
            AssertParseEvaluate(p, "@(Boolean)", state, true);
            AssertParseEvaluate(p, "@(Boolean) == true", state, true);
            AssertParseEvaluate(p, "'@(Empty, ';')' == ''", state, true);}
开发者ID:nikson,项目名称:msbuild,代码行数:32,代码来源:ExpressionTree_Tests.cs

示例15: 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


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