Skip to content

Instantly share code, notes, and snippets.

@ArsenShnurkov
Last active December 1, 2015 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArsenShnurkov/479cefd3f0ae74325cae to your computer and use it in GitHub Desktop.
Save ArsenShnurkov/479cefd3f0ae74325cae to your computer and use it in GitHub Desktop.
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
Copy link
Author

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