Exemplo n.º 1
0
        public string GetEvaluatedMetadata(string attributeName)
        {
            if (this.IsVirtual)
            {
                // For virtual items, use our virtual property collection
                if (!virtualProperties.ContainsKey(attributeName))
                {
                    return(String.Empty);
                }
                return(virtualProperties[attributeName]);
            }

            // cannot ask MSBuild for Include, so intercept it and return the corresponding property
            if (String.Compare(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(item.FinalItemSpec);
            }

            // Build Action is the type, not a property, so intercept this one as well
            if (String.Compare(attributeName, ProjectFileConstants.BuildAction, StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(item.Name);
            }

            return(item.GetEvaluatedMetadata(attributeName));
        }
Exemplo n.º 2
0
        public void ConstructHasMetadata()
        {
            BuildItem item = new BuildItem("m", "v");

            Assertion.AssertEquals(false, item.HasMetadata("m"));
            Assertion.AssertEquals(string.Empty, item.GetEvaluatedMetadata("m"));
            Assertion.AssertEquals(string.Empty, item.GetMetadata("m"));
            Assertion.AssertEquals(builtInMetadataNames.Length, item.MetadataCount);
            Assertion.AssertEquals(0, item.CustomMetadataCount);
        }
Exemplo n.º 3
0
		public void TestSetMetadata3 ()
		{
			item = new BuildItem ("name", "include");
			item.SetMetadata ("a", "$(A)");
			item.SetMetadata ("b", "$(A)", true);
			item.SetMetadata ("c", "$(A)", false);

			Assert.AreEqual ("$(A)", item.GetEvaluatedMetadata ("a"), "A1");
			Assert.AreEqual ("$(A)", item.GetEvaluatedMetadata ("b"), "A2");
			Assert.AreEqual ("$(A)", item.GetEvaluatedMetadata ("c"), "A3");
			Assert.AreEqual ("$(A)", item.GetMetadata ("a"), "A4");
			Assert.AreEqual (Utilities.Escape ("$(A)"), item.GetMetadata ("b"), "A5");
			Assert.AreEqual ("$(A)", item.GetMetadata ("c"), "A6");
		}
Exemplo n.º 4
0
		public void TestGetEvaluatedMetadata1 ()
		{
			string itemName = "a";
			string itemInclude = "a";
			string metadataName = "name";
			string metadataValue = "a;b;c";

			item = new BuildItem (itemName, itemInclude);

			Assert.AreEqual (String.Empty, item.GetEvaluatedMetadata (metadataName), "A1");

			item.SetMetadata (metadataName, metadataValue);

			Assert.AreEqual (metadataValue, item.GetEvaluatedMetadata (metadataName), "A2");
			Assert.AreEqual (itemInclude, item.GetEvaluatedMetadata ("Identity"), "A3");
		}
Exemplo n.º 5
0
		public void TestCopyCustomMetadataTo1 ()
		{
			BuildItem source, destination;
			string itemName1 = "a";
			string itemName2 = "b";
			string itemInclude = "a;b;c";
			string metadataName = "name";
			string metadataValue = "value";

			source = new BuildItem (itemName1, itemInclude);
			destination = new BuildItem (itemName2, itemInclude);

			source.SetMetadata (metadataName, metadataValue);

			source.CopyCustomMetadataTo (destination);

			Assert.AreEqual (metadataValue, destination.GetMetadata (metadataName), "A1");
			Assert.AreEqual (metadataValue, destination.GetEvaluatedMetadata (metadataName), "A2");
		}
Exemplo n.º 6
0
		static void CheckBuildItem (BuildItem item, string name, string [,] metadata, string finalItemSpec, string prefix)
		{
			Assert.AreEqual (name, item.Name, prefix + "#1");
			for (int i = 0; i < metadata.GetLength (0); i++) {
				string key = metadata [i, 0];
				string val = metadata [i, 1];
				Assert.IsTrue (item.HasMetadata (key), String.Format ("{0}#2: Expected metadata '{1}' not found", prefix, key));
				Assert.AreEqual (val, item.GetMetadata (key), String.Format ("{0}#3: Value for metadata {1}", prefix, key));
				Assert.AreEqual (val, item.GetEvaluatedMetadata (key), String.Format ("{0}#4: Value for evaluated metadata {1}", prefix, key));
			}
			Assert.AreEqual (finalItemSpec, item.FinalItemSpec, prefix + "#5");
		}
Exemplo n.º 7
0
		string EvaluateMetadata (BuildItem it, string metadata)
		{
			var d = it.GetEvaluatedMetadata (metadata);
			if (string.IsNullOrEmpty (d))
				return null;
			else
				return d;
		}
 public override IEnumerable<Tuple<string, string>> GetEvaluatedMetadata(BuildItem proj)
 {
     return proj.MetadataNames.Cast<string>().Select(k => Tuple.Create(k, proj.GetEvaluatedMetadata(k)));
 }
Exemplo n.º 9
0
		public void GetMetadata_EscapedItemSpec ()
		{
			string itemInclude = "a;b;c";
			string escapedItemInclude = Utilities.Escape (itemInclude);

			item = new BuildItem ("name", escapedItemInclude);
			Assert.IsTrue (item.GetMetadata ("FullPath").EndsWith (escapedItemInclude), "#1a");
			Assert.IsTrue (item.GetEvaluatedMetadata ("FullPath").EndsWith (itemInclude), "#1b");

			Assert.AreEqual (escapedItemInclude, item.GetMetadata ("FileName"), "#2b");
			Assert.AreEqual (itemInclude, item.GetEvaluatedMetadata ("FileName"), "#2b");

			Assert.AreEqual (escapedItemInclude, item.GetMetadata ("Identity"), "#3a");
			Assert.AreEqual ("a;b;c", item.GetEvaluatedMetadata ("Identity"), "#3b");
		}