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


C# TaskItem.GetMetadata方法代码示例

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


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

示例1: CopyMetadataFromITaskItem

        public void CopyMetadataFromITaskItem()
        {
            TaskItem from = new TaskItem();
            from.ItemSpec = "Monkey.txt";
            from.SetMetadata("Dog", "Bingo");
            from.SetMetadata("Cat", "Morris");
            from.SetMetadata("Bird", "Big");

            TaskItem to = new TaskItem();
            to.ItemSpec = "Bonobo.txt";
            to.SetMetadata("Sponge", "Bob");
            to.SetMetadata("Dog", "Harriet");
            to.SetMetadata("Cat", "Mike");
            from.CopyMetadataTo(to);

            Assert.AreEqual("Bonobo.txt", to.ItemSpec);          // ItemSpec is never overwritten
            Assert.AreEqual("Bob", to.GetMetadata("Sponge"));   // Metadata not in source are preserverd.
            Assert.AreEqual("Harriet", to.GetMetadata("Dog"));  // Metadata present on destination are not overwritten.
            Assert.AreEqual("Mike", to.GetMetadata("Cat"));
            Assert.AreEqual("Big", to.GetMetadata("Bird"));
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:21,代码来源:TaskItem_Tests.cs

示例2: ReturnsFirstOne

 public void ReturnsFirstOne()
 {
     FindInList f = new FindInList();
     f.BuildEngine = new MockEngine();
     f.ItemSpecToFind = "a.cs";
     ITaskItem item1 = new TaskItem("a.cs");
     item1.SetMetadata("id", "1");
     ITaskItem item2 = new TaskItem("a.cs");
     item2.SetMetadata("id", "2");
     f.List = new ITaskItem[] { item1, item2 };
     Assert.True(f.Execute());
     Assert.Equal("a.cs", f.ItemFound.ItemSpec);
     Assert.Equal(item1.GetMetadata("id"), f.ItemFound.GetMetadata("id"));
 }
开发者ID:cameron314,项目名称:msbuild,代码行数:14,代码来源:FindInList_Tests.cs

示例3: AddLibraryName

 /// <summary>
 /// Add all items to the command line
 /// </summary>
 private static void AddLibraryName(IEnumerable<ITaskItem> items, List<ITaskItem> outputItems)
 {
     if (items == null) return;
     foreach (var x in items)
     {
         var outputItem = new TaskItem(x);
         x.CopyMetadataTo(outputItem);
         if (string.IsNullOrEmpty(outputItem.GetMetadata("LibraryName")))
         {
             outputItem.SetMetadata("LibraryName", Path.GetFileNameWithoutExtension(x.ItemSpec));
         }
         outputItems.Add(outputItem);
     }
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:17,代码来源:AssignLibraryName.cs

示例4: ReturnsLastOne

 public void ReturnsLastOne()
 {
     FindInList f = new FindInList();
     f.BuildEngine = new MockEngine();
     f.ItemSpecToFind = "a.cs";
     f.FindLastMatch = true;
     ITaskItem item1 = new TaskItem("a.cs");
     item1.SetMetadata("id", "1");
     ITaskItem item2 = new TaskItem("a.cs");
     item2.SetMetadata("id", "2");
     f.List = new ITaskItem[] { item1, item2 };
     Assert.IsTrue(f.Execute(), "Expect success");
     Assert.AreEqual("a.cs", f.ItemFound.ItemSpec);
     Assert.AreEqual(item2.GetMetadata("id"), f.ItemFound.GetMetadata("id"));
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:15,代码来源:FindInList_Tests.cs

示例5: ConstructWithITaskItem

        public void ConstructWithITaskItem()
        {
            TaskItem from = new TaskItem();
            from.ItemSpec = "Monkey.txt";
            from.SetMetadata("Dog", "Bingo");
            from.SetMetadata("Cat", "Morris");

            TaskItem to = new TaskItem((ITaskItem)from);
            Assert.AreEqual("Monkey.txt", to.ItemSpec);
            Assert.AreEqual("Monkey.txt", (string)to);
            Assert.AreEqual("Bingo", to.GetMetadata("Dog"));
            Assert.AreEqual("Morris", to.GetMetadata("Cat"));

            // Test that item metadata are case-insensitive.
            to.SetMetadata("CaT", "");
            Assert.AreEqual("", to.GetMetadata("Cat"));

            // manipulate the item-spec a bit
            Assert.AreEqual("Monkey", to.GetMetadata(FileUtilities.ItemSpecModifiers.Filename));
            Assert.AreEqual(".txt", to.GetMetadata(FileUtilities.ItemSpecModifiers.Extension));
            Assert.AreEqual(String.Empty, to.GetMetadata(FileUtilities.ItemSpecModifiers.RelativeDir));
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:22,代码来源:TaskItem_Tests.cs

示例6: CreateTaskItemWithNullMetadata

        public void CreateTaskItemWithNullMetadata()
        {
            IDictionary<string, string> metadata = new Dictionary<string, string>();
            metadata.Add("m", null);

            TaskItem item = new TaskItem("bar", (IDictionary)metadata);
            Assert.AreEqual(String.Empty, item.GetMetadata("m"));
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:8,代码来源:TaskItem_Tests.cs

示例7: SetNullMetadataValue

 public void SetNullMetadataValue()
 {
     TaskItem item = new TaskItem("bar");
     item.SetMetadata("m", null);
     Assert.AreEqual(String.Empty, item.GetMetadata("m"));
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:6,代码来源:TaskItem_Tests.cs

示例8: NonexistentRequestIdentity

 public void NonexistentRequestIdentity()
 {
     TaskItem from = new TaskItem();
     from.ItemSpec = "Monkey.txt";
     Assert.AreEqual
     (
         "Monkey.txt",
         from.GetMetadata(FileUtilities.ItemSpecModifiers.Identity)
     );
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:10,代码来源:TaskItem_Tests.cs

示例9: RequestTimeStamps

        public void RequestTimeStamps()
        {
            TaskItem from = new TaskItem();
            from.ItemSpec = FileUtilities.GetTemporaryFile();

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.ModifiedTime).Length > 0
            );

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.CreatedTime).Length > 0
            );

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.AccessedTime).Length > 0
            );

            File.Delete(from.ItemSpec);

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.ModifiedTime).Length == 0
            );

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.CreatedTime).Length == 0
            );

            Assert.IsTrue
            (
                from.GetMetadata(FileUtilities.ItemSpecModifiers.AccessedTime).Length == 0
            );
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:37,代码来源:TaskItem_Tests.cs

示例10: TestCtor_EscapedSpecialChar_BrokenEscaping

		public void TestCtor_EscapedSpecialChar_BrokenEscaping ()
		{
			// This is badly escaped, but MSBuild does not care.
			var metadata = "foo%[email protected]";
			var item = new TaskItem (metadata);

			Assert.AreEqual (metadata, item.ItemSpec, "#1");
			Assert.AreEqual (metadata, item.GetMetadata ("Identity"), "#2");
			Assert.AreEqual (Path.GetFileNameWithoutExtension (metadata), item.GetMetadata ("FileName"), "#3");
			Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (metadata), "#4");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:TaskItemTest.cs

示例11: TestReferenceWithMetadataAlreadySetBuildInProjectAttributeFalse

        public void TestReferenceWithMetadataAlreadySetBuildInProjectAttributeFalse()
        {
            // Test the case where the metadata is missing and we are not supposed to build the reference
            ITaskItem referenceItem = new TaskItem("TestItem");
            referenceItem.SetMetadata("BuildReference", "true");
            referenceItem.SetMetadata("ReferenceOutputAssembly", "true");

            XmlDocument doc = new XmlDocument();
            XmlElement element = doc.CreateElement("TestElement");
            element.SetAttribute("BuildProjectInSolution", "false");
            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(true, referenceItem, element);
            Assert.IsTrue(referenceItem.GetMetadata("BuildReference").Equals("true", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(referenceItem.GetMetadata("ReferenceOutputAssembly").Equals("true", StringComparison.OrdinalIgnoreCase));

            // Test the case where only ReferenceOutputAssembly is not set
            referenceItem = new TaskItem("TestItem");
            referenceItem.SetMetadata("BuildReference", "true");
            doc = new XmlDocument();
            element = doc.CreateElement("TestElement");
            element.SetAttribute("BuildProjectInSolution", "false");
            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(true, referenceItem, element);
            Assert.IsTrue(referenceItem.GetMetadata("BuildReference").Equals("true", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(referenceItem.GetMetadata("ReferenceOutputAssembly").Equals("false", StringComparison.OrdinalIgnoreCase));

            // Test the case where only BuildReference is not set
            referenceItem = new TaskItem("TestItem");
            referenceItem.SetMetadata("ReferenceOutputAssembly", "true");
            doc = new XmlDocument();
            element = doc.CreateElement("TestElement");
            element.SetAttribute("BuildProjectInSolution", "false");
            AssignProjectConfiguration.SetBuildInProjectAndReferenceOutputAssemblyMetadata(true, referenceItem, element);
            Assert.IsTrue(referenceItem.GetMetadata("BuildReference").Equals("false", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(referenceItem.GetMetadata("ReferenceOutputAssembly").Equals("true", StringComparison.OrdinalIgnoreCase));
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:34,代码来源:AssignProjectConfiguration_Tests.cs

示例12: NonexistentRequestRootDir

 public void NonexistentRequestRootDir()
 {
     TaskItem from = new TaskItem();
     from.ItemSpec = "Monkey.txt";
     Assert.AreEqual
     (
         Path.GetPathRoot
         (
             from.GetMetadata(FileUtilities.ItemSpecModifiers.FullPath)
         ),
         from.GetMetadata(FileUtilities.ItemSpecModifiers.RootDir)
     );
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:13,代码来源:TaskItem_Tests.cs

示例13: CheckSetCopyLocalToFalseOnGacAssemblies

        public void CheckSetCopyLocalToFalseOnGacAssemblies()
        {
            string gacPath = @"C:\windows\gac";

            ResolveComReference rcr = new ResolveComReference();
            rcr.BuildEngine = new MockEngine();

            ArrayList taskItems = new ArrayList();
            TaskItem nonGacNoPrivate = new TaskItem(@"C:\windows\gar\test1.dll");
            TaskItem gacNoPrivate = new TaskItem(@"C:\windows\gac\assembly1.dll");

            TaskItem nonGacPrivateFalse = new TaskItem(@"C:\windows\gar\test1.dll");
            nonGacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false");
            TaskItem gacPrivateFalse = new TaskItem(@"C:\windows\gac\assembly1.dll");
            gacPrivateFalse.SetMetadata(ItemMetadataNames.privateMetadata, "false");

            TaskItem nonGacPrivateTrue = new TaskItem(@"C:\windows\gar\test1.dll");
            nonGacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true");
            TaskItem gacPrivateTrue = new TaskItem(@"C:\windows\gac\assembly1.dll");
            gacPrivateTrue.SetMetadata(ItemMetadataNames.privateMetadata, "true");

            taskItems.Add(nonGacNoPrivate);
            taskItems.Add(gacNoPrivate);

            taskItems.Add(nonGacPrivateFalse);
            taskItems.Add(gacPrivateFalse);

            taskItems.Add(nonGacPrivateTrue);
            taskItems.Add(gacPrivateTrue);

            rcr.SetCopyLocalToFalseOnGacOrNoPIAAssemblies(taskItems, gacPath);

            // if Private is missing, by default GAC items are CopyLocal=false, non GAC CopyLocal=true
            Assert.IsTrue(nonGacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Non Gac assembly, missing Private, should be TRUE");

            Assert.IsTrue(gacNoPrivate.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Gac assembly, missing Private, should be FALSE");

            // if Private is set, it takes precedence
            Assert.IsTrue(nonGacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Non Gac assembly, Private false, should be FALSE");

            Assert.IsTrue(gacPrivateFalse.GetMetadata(ItemMetadataNames.copyLocal) == "false", "Gac assembly, Private false, should be FALSE");

            Assert.IsTrue(nonGacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Non Gac assembly, Private true, should be TRUE");

            Assert.IsTrue(gacPrivateTrue.GetMetadata(ItemMetadataNames.copyLocal) == "true", "Gac assembly, Private true, should be TRUE");
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:46,代码来源:ResolveComReference_Tests.cs

示例14: ConstructFromDictionary

        public void ConstructFromDictionary()
        {
            Hashtable h = new Hashtable();
            h[FileUtilities.ItemSpecModifiers.Filename] = "foo";
            h[FileUtilities.ItemSpecModifiers.Extension] = "bar";
            h["custom"] = "hello";

            TaskItem t = new TaskItem("bamboo.baz", h);

            // item-spec modifiers were not overridden by dictionary passed to constructor
            Assert.AreEqual("bamboo", t.GetMetadata(FileUtilities.ItemSpecModifiers.Filename));
            Assert.AreEqual(".baz", t.GetMetadata(FileUtilities.ItemSpecModifiers.Extension));
            Assert.AreEqual("hello", t.GetMetadata("CUSTOM"));
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:14,代码来源:TaskItem_Tests.cs

示例15: NonexistentRequestFullPath

 public void NonexistentRequestFullPath()
 {
     TaskItem from = new TaskItem();
     from.ItemSpec = "Monkey.txt";
     Assert.AreEqual
     (
         Path.Combine
         (
             Directory.GetCurrentDirectory(),
             "Monkey.txt"
         ),
         from.GetMetadata(FileUtilities.ItemSpecModifiers.FullPath)
     );
 }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:14,代码来源:TaskItem_Tests.cs


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