Merge pull request #112 from skolima/master
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Construction / ProjectItemElement.cs
index 8c4a62ebb57c13e76c2bba072c5d6264e4e52c5e..02a1a6ec4995f231f27bcc7501802ee4043cb2c2 100644 (file)
@@ -26,6 +26,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using Microsoft.Build.Internal;
@@ -33,6 +34,8 @@ using System.Xml;
 
 namespace Microsoft.Build.Construction
 {
+        [System.Diagnostics.DebuggerDisplayAttribute ("{ItemType} Include={Include} Exclude={Exclude} "
+                                                      + "#Metadata={Count} Condition={Condition}")]
         public class ProjectItemElement : ProjectElementContainer
         {
                 internal ProjectItemElement (string itemType, ProjectRootElement containingProject)
@@ -40,47 +43,62 @@ namespace Microsoft.Build.Construction
                         ItemType = itemType;
                         ContainingProject = containingProject;
                 }
-
-                public string Exclude { get; set; }
+                string exclude;
+                public string Exclude { get { return exclude ?? String.Empty; } set { exclude = value; } }
                 public bool HasMetadata {
                         get {
                                 var metadata = Metadata.FirstOrDefault ();
                                 return metadata != null;
                         }
                 }
-
-                public string Include { get; set; }
-                public string ItemType { get; set; }
+                string include;
+                public string Include { get { return include ?? String.Empty; } set { include = value; } }
+                string itemType;
+                public string ItemType { get { return itemType ?? String.Empty; } set { itemType = value; } }
                 public ICollection<ProjectMetadataElement> Metadata {
-                        get { return new CollectionFromEnumerable<ProjectMetadataElement> (Children.
-                                Where (p => p as ProjectMetadataElement != null).
-                                Select (p => (ProjectMetadataElement)p)); }
+                        get { return new CollectionFromEnumerable<ProjectMetadataElement> (
+                                new FilteredEnumerable<ProjectMetadataElement> (Children)); }
                 }
-                public string Remove { get; set; }
-
+                string @remove;
+                public string Remove { get { return @remove ?? String.Empty; } set { @remove = value; } }
                 public ProjectMetadataElement AddMetadata (string name, string unevaluatedValue)
                 {
                         var metadata = ContainingProject.CreateMetadataElement (name, unevaluatedValue);
                         AppendChild (metadata);
                         return metadata;
                 }
-
                 internal override string XmlName {
                         get { return ItemType; }
                 }
-
-                internal override void Save (XmlWriter writer)
+                internal override void SaveValue (XmlWriter writer)
+                {
+                        SaveAttribute (writer, "Include", Include);
+                        SaveAttribute (writer, "Exclude", Exclude);
+                        SaveAttribute (writer, "Remove", Remove);
+                        base.SaveValue (writer);
+                }
+                internal override void LoadAttribute (string name, string value)
+                {
+                        switch (name) {
+                        case "Include":
+                                Include = value;
+                                break;
+                        case "Exclude":
+                                Exclude = value;
+                                break;
+                        case "Remove":
+                                Remove = value;
+                                break;
+                        default:
+                                base.LoadAttribute (name, value);
+                                break;
+                        }
+                }
+                internal override ProjectElement LoadChildElement (string name)
                 {
-                        writer.WriteStartElement (XmlName);
-                        if (!string.IsNullOrWhiteSpace (Include))
-                                writer.WriteAttributeString ("Include", Include);
-                        if (!string.IsNullOrWhiteSpace (Exclude))
-                                writer.WriteAttributeString ("Exclude", Exclude);
-                        if (!string.IsNullOrWhiteSpace (Remove))
-                                writer.WriteAttributeString ("Remove", Remove);
-                        foreach (var child in Children)
-                                child.Save (writer);
-                        writer.WriteEndElement ();
+                        var metadata = ContainingProject.CreateMetadataElement (name);
+                        AppendChild (metadata);
+                        return metadata;
                 }
         }
 }