public override void Save(string filename)
        {
            XmlWriter w = (XmlWriter)null;

            try
            {
                if (this.PreserveWhitespace)
                {
                    XmlFormatter.Format((XmlDocument)this);
                    w = (XmlWriter) new XmlAttributePreservingWriter(filename, this.TextEncoding);
                }
                else
                {
                    w = (XmlWriter) new XmlTextWriter(filename, this.TextEncoding)
                    {
                        Formatting = Formatting.Indented
                    }
                };
                this.WriteTo(w);
            }
            finally
            {
                if (w != null)
                {
                    w.Flush();
                    w.Close();
                }
            }
        }
 internal void UpdatePreservationInfo(XmlAttributeCollection updatedAttributes, XmlFormatter formatter)
 {
     if (updatedAttributes.Count == 0)
     {
         if (this.orderedAttributes.Count <= 0)
             return;
         this.leadingSpaces.Clear();
         this.orderedAttributes.Clear();
     }
     else
     {
         Dictionary<string, bool> dictionary = new Dictionary<string, bool>();
         foreach (string index in this.orderedAttributes)
             dictionary[index] = false;
         foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap)updatedAttributes)
         {
             if (!dictionary.ContainsKey(xmlAttribute.Name))
                 this.orderedAttributes.Add(xmlAttribute.Name);
             dictionary[xmlAttribute.Name] = true;
         }
         bool flag1 = true;
         string str = (string)null;
         foreach (string key in this.orderedAttributes)
         {
             bool flag2 = dictionary[key];
             if (!flag2)
             {
                 if (this.leadingSpaces.ContainsKey(key))
                 {
                     string space = this.leadingSpaces[key];
                     if (flag1)
                     {
                         if (str == null)
                             str = space;
                     }
                     else if (this.ContainsNewLine(space))
                         str = space;
                     this.leadingSpaces.Remove(key);
                 }
             }
             else if (str != null)
             {
                 if (flag1 || !this.leadingSpaces.ContainsKey(key) || !this.ContainsNewLine(this.leadingSpaces[key]))
                     this.leadingSpaces[key] = str;
                 str = (string)null;
             }
             else if (!this.leadingSpaces.ContainsKey(key))
             {
                 if (flag1)
                     this.leadingSpaces[key] = " ";
                 else if (this.OneAttributePerLine)
                     this.leadingSpaces[key] = this.GetAttributeNewLineString(formatter);
                 else
                     this.EnsureAttributeNewLineString(formatter);
             }
             flag1 = flag1 && !flag2;
         }
     }
 }
 public string GetAttributeNewLineString(XmlFormatter formatter)
 {
     if (this.attributeNewLineString == null)
     {
         this.attributeNewLineString = this.ComputeAttributeNewLineString(formatter);
     }
     return(this.attributeNewLineString);
 }
        private string ComputeAttributeNewLineString(XmlFormatter formatter)
        {
            string str = this.LookAheadForNewLineString();

            if (str != null)
            {
                return(str);
            }
            if (formatter != null)
            {
                return(formatter.CurrentAttributeIndent);
            }
            else
            {
                return((string)null);
            }
        }
 public string GetAttributeNewLineString(XmlFormatter formatter)
 {
     if (this.attributeNewLineString == null)
         this.attributeNewLineString = this.ComputeAttributeNewLineString(formatter);
     return this.attributeNewLineString;
 }
 private void EnsureAttributeNewLineString(XmlFormatter formatter)
 {
     this.GetAttributeNewLineString(formatter);
 }
 private string ComputeAttributeNewLineString(XmlFormatter formatter)
 {
     string str = this.LookAheadForNewLineString();
     if (str != null)
         return str;
     if (formatter != null)
         return formatter.CurrentAttributeIndent;
     else
         return (string)null;
 }
 internal void UpdatePreservationInfo(XmlAttributeCollection updatedAttributes, XmlFormatter formatter)
 {
     if (updatedAttributes.Count == 0)
     {
         if (this.orderedAttributes.Count <= 0)
         {
             return;
         }
         this.leadingSpaces.Clear();
         this.orderedAttributes.Clear();
     }
     else
     {
         Dictionary <string, bool> dictionary = new Dictionary <string, bool>();
         foreach (string index in this.orderedAttributes)
         {
             dictionary[index] = false;
         }
         foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap)updatedAttributes)
         {
             if (!dictionary.ContainsKey(xmlAttribute.Name))
             {
                 this.orderedAttributes.Add(xmlAttribute.Name);
             }
             dictionary[xmlAttribute.Name] = true;
         }
         bool   flag1 = true;
         string str   = (string)null;
         foreach (string key in this.orderedAttributes)
         {
             bool flag2 = dictionary[key];
             if (!flag2)
             {
                 if (this.leadingSpaces.ContainsKey(key))
                 {
                     string space = this.leadingSpaces[key];
                     if (flag1)
                     {
                         if (str == null)
                         {
                             str = space;
                         }
                     }
                     else if (this.ContainsNewLine(space))
                     {
                         str = space;
                     }
                     this.leadingSpaces.Remove(key);
                 }
             }
             else if (str != null)
             {
                 if (flag1 || !this.leadingSpaces.ContainsKey(key) || !this.ContainsNewLine(this.leadingSpaces[key]))
                 {
                     this.leadingSpaces[key] = str;
                 }
                 str = (string)null;
             }
             else if (!this.leadingSpaces.ContainsKey(key))
             {
                 if (flag1)
                 {
                     this.leadingSpaces[key] = " ";
                 }
                 else if (this.OneAttributePerLine)
                 {
                     this.leadingSpaces[key] = this.GetAttributeNewLineString(formatter);
                 }
                 else
                 {
                     this.EnsureAttributeNewLineString(formatter);
                 }
             }
             flag1 = flag1 && !flag2;
         }
     }
 }
 private void EnsureAttributeNewLineString(XmlFormatter formatter)
 {
     this.GetAttributeNewLineString(formatter);
 }
 void IXmlFormattableAttributes.FormatAttributes(XmlFormatter formatter)
 {
     this.preservationDict.UpdatePreservationInfo(this.Attributes, formatter);
 }
 void IXmlFormattableAttributes.FormatAttributes(XmlFormatter formatter)
 {
     this.preservationDict.UpdatePreservationInfo(this.Attributes, formatter);
 }