Last active
December 1, 2015 06:10
-
-
Save ArsenShnurkov/479cefd3f0ae74325cae to your computer and use it in GitHub Desktop.
corrected test example for issue 2710
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the output is
without XML declaration first line.