Exemple #1
0
        public void RemoveMetadata(string metadataName)
        {
            if (metadataName == null)
            {
                throw new ArgumentNullException("metadataName");
            }

            if (ReservedNameUtils.IsReservedMetadataName(metadataName))
            {
                throw new ArgumentException(String.Format("\"{0}\" is a reserved item meta-data, and cannot be modified or deleted.",
                                                          metadataName));
            }

            if (FromXml)
            {
                if (unevaluatedMetadata.Contains(metadataName))
                {
                    XmlNode node = itemElement [metadataName];
                    itemElement.RemoveChild(node);
                }
            }
            else if (HasParentItem)
            {
                if (parent_item.child_items.Count > 1)
                {
                    SplitParentItem();
                }
                parent_item.RemoveMetadata(metadataName);
            }

            DeleteMetadata(metadataName);
        }
        /// <summary>
        /// Set an attribute on the project element
        /// </summary>
        /// <param name="attributeName">Name of the attribute to set</param>
        /// <param name="attributeValue">Value to give to the attribute</param>
        public void SetMetadata(string attributeName, string attributeValue)
        {
            Debug.Assert(String.Compare(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase) != 0, "Use rename as this won't work");

            if (this.IsVirtual)
            {
                // For virtual node, use our virtual property collection
                if (virtualProperties.ContainsKey(attributeName))
                {
                    virtualProperties.Remove(attributeName);
                }
                virtualProperties.Add(attributeName, attributeValue);
                return;
            }

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

            // Check out the project file.
            if (!this.itemProject.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            if (attributeValue == null)
            {
                item.RemoveMetadata(attributeName);
            }
            else
            {
                item.SetMetadata(attributeName, attributeValue);
            }
            itemProject.SetProjectFileDirty(true);
        }
Exemple #3
0
		public void TestRemoveMetadata4 ()
		{
			item = new BuildItem ("name", "value");
			item.RemoveMetadata ("Filename");
		}
Exemple #4
0
		public void TestRemoveMetadata3 ()
		{
			item = new BuildItem ("name", "value");
			item.RemoveMetadata ("undefined_metadata");
		}
Exemple #5
0
		public void TestRemoveMetadata2 ()
		{
			item = new BuildItem ("name", "value");
			item.RemoveMetadata (null);
		}
Exemple #6
0
		public void TestRemoveMetadata1 ()
		{
			string itemName = "a";
			string itemInclude = "a";
			string metadataName = "name";
			string metadataValue = "a;b;c";

			item = new BuildItem (itemName, itemInclude);

			item.SetMetadata (metadataName, metadataValue);

			Assert.AreEqual (true, item.HasMetadata (metadataName), "A1");

			item.RemoveMetadata (metadataName);

			Assert.AreEqual (false, item.HasMetadata (metadataName), "A2");
		}