Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
corrected test example for issue 2710
using System;
using System.Xml;
using System.Configuration;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.IO;
using System.Globalization;
class Clobals
{
public static void Main (string[] args)
{
Settings.Default.WindowPositions = new WindowPositionList ();
//Settings.Default.Save ();
Console.WriteLine(SerializedValue(Settings.Default.WindowPositions));
}
public static string SerializedValue(object propertyValue)
{
XmlSerializer serializer = new XmlSerializer (propertyValue.GetType ());
using (StringWriter stream = new StringWriter(CultureInfo.InvariantCulture))
{
var settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
using (var writer = XmlWriter.Create (stream, settings))
{
var emptyNamepsaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
serializer.Serialize (writer, propertyValue, emptyNamepsaces);
} // writer.Flush happens here
var serializedValue = stream.ToString ();
return serializedValue;
}
}
}
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized (new Settings ())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute ()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute ()]
public WindowPositionList WindowPositions {
get {
return ((WindowPositionList)(this ["WindowPositions"]));
}
set {
this ["WindowPositions"] = value;
}
}
}
[Serializable]
public class WindowPositionList : IXmlSerializable
{
public XmlSchema GetSchema ()
{
return null;
}
public void ReadXml (XmlReader reader)
{
reader.ReadStartElement ("WindowPositions");
reader.ReadEndElement ();
}
public void WriteXml (XmlWriter writer)
{
writer.WriteStartElement ("WindowPositions");
writer.WriteEndElement ();
}
}
@ArsenShnurkov

This comment has been minimized.

Copy link
Owner Author

@ArsenShnurkov ArsenShnurkov commented Dec 1, 2015

the output is

<WindowPositionList><WindowPositions /></WindowPositionList>

without XML declaration first line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment