Innovatian.Configuration.XmlConfigurationSource.ToXml C# (CSharp) Method

ToXml() public static method

Converts the given IConfigurationSection to an XML representation.
public static ToXml ( IConfigurationSection section ) : System.Xml.Linq.XElement
section IConfigurationSection /// The section to convert to XML. ///
return System.Xml.Linq.XElement
        public static XElement ToXml( IConfigurationSection section )
        {
            if ( section == null )
            {
                throw new ArgumentNullException( "section" );
            }

            var xml = new XElement( "Section", new XAttribute( "Name", section.Name ),
                                    from setting in section
                                    select new XElement( "Key",
                                                         new XAttribute( "Name", setting.Key ),
                                                         new XAttribute( "Value", setting.Value )
                                        )
                );
            return xml;
        }

Same methods

XmlConfigurationSource::ToXml ( IEnumerable sections ) : string

Usage Example

 /// <summary>
 /// Saves all sections. All data merged from other merged sources will
 /// be included.
 /// </summary>
 public override void Save()
 {
     using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetStore(Scope, null, null))
     {
         using (var isoStream =
                    new IsolatedStorageFileStream(_fileName,
                                                  FileMode.Truncate,
                                                  FileAccess.Write,
                                                  FileShare.Read,
                                                  isolatedStorageFile))
         {
             string xml      = XmlConfigurationSource.ToXml(Sections.Values);
             byte[] xmlBytes = Encoding.UTF8.GetBytes(xml);
             isoStream.Write(xmlBytes, 0, xmlBytes.Length);
             isoStream.Flush();
         }
     }
 }