Fix ProjectRootElement.DirectoryPath. Add unit test for ProjectRootElement.
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Construction / ProjectExtensionsElement.cs
index 041a121c1e6cd574652ac121013785a48cae2429..d6bcbbb12bcfe947a8d77148327e6d197d623a48 100644 (file)
 
 using System;
 using System.Xml;
+using System.Text;
 
 namespace Microsoft.Build.Construction
 {
         public class ProjectExtensionsElement : ProjectElement
         {
-                public string Content { get; set; }
+                internal ProjectExtensionsElement (ProjectRootElement containingProject)
+                {
+                        ContainingProject = containingProject;
+                }
+                public override string Condition {
+                        get { return null; }
+                        set {
+                                throw new InvalidOperationException ("Can not set Condition.");
+                        }
+                }
+                public string Content {
+                        get { return element.InnerXml; }
+                        set { element.InnerXml = value; }
+                }
                 public string this[string name] {
                         get {
-                                throw new NotImplementedException ();
+                                var child = element[name];
+                                return child == null ? string.Empty : child.InnerXml;
+                        }
+                        set {
+                                var child = element[name];
+                                if (child == null) {
+                                        if (string.IsNullOrEmpty (name))
+                                                return;
+                                        child = document.CreateElement (name);
+                                        element.AppendChild (child);
+                                }
+                                if (string.IsNullOrEmpty (value))
+                                        element.RemoveChild (child);
+                                else
+                                        child.InnerXml = value;
                         }
-                        set { }
                 }
-                internal override string XmlName {
-                        get {
-                                throw new NotImplementedException ();
+                internal override void Load (XmlReader reader)
+                {
+                        while (reader.Read () && reader.NodeType != XmlNodeType.Element)
+                                ;
+                        using (XmlReader subReader = reader.ReadSubtree ()) {
+                                document = new XmlDocument ();
+                                document.Load (subReader);
+                                element = document.DocumentElement;
                         }
                 }
-                internal override void Save (XmlWriter writer)
+                internal override void SaveValue (XmlWriter writer)
                 {
-                        throw new NotImplementedException ();
+                        element.WriteContentTo (writer);
+                }
+                internal override string XmlName {
+                        get { return "ProjectExtensions"; }
                 }
+                XmlDocument document;
+                XmlElement element;
         }
 }