Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. using System;
  2. using System.Xml;
  3. using System.Configuration;
  4. using System.Xml.Serialization;
  5. using System.Xml.Schema;
  6. using System.IO;
  7. using System.Globalization;
  8.  
  9. class Clobals
  10. {
  11. public static void Main (string[] args)
  12. {
  13. Settings.Default.WindowPositions = new WindowPositionList ();
  14. //Settings.Default.Save ();
  15. Console.WriteLine(SerializedValue(Settings.Default.WindowPositions));
  16. }
  17. public static string SerializedValue(object propertyValue)
  18. {
  19. XmlSerializer serializer = new XmlSerializer (propertyValue.GetType ());
  20. using (StringWriter stream = new StringWriter(CultureInfo.InvariantCulture))
  21. {
  22. var settings = new XmlWriterSettings();
  23. settings.OmitXmlDeclaration = true;
  24. using (var writer = XmlWriter.Create (stream, settings))
  25. {
  26. var emptyNamepsaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
  27. serializer.Serialize (writer, propertyValue, emptyNamepsaces);
  28. } // writer.Flush happens here
  29. var serializedValue = stream.ToString ();
  30. return serializedValue;
  31. }
  32. }
  33. }
  34.  
  35. internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
  36. {
  37. private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized (new Settings ())));
  38.  
  39. public static Settings Default {
  40. get {
  41. return defaultInstance;
  42. }
  43. }
  44.  
  45. [global::System.Configuration.UserScopedSettingAttribute ()]
  46. [global::System.Diagnostics.DebuggerNonUserCodeAttribute ()]
  47. public WindowPositionList WindowPositions {
  48. get {
  49. return ((WindowPositionList)(this ["WindowPositions"]));
  50. }
  51. set {
  52. this ["WindowPositions"] = value;
  53. }
  54. }
  55.  
  56. }
  57.  
  58. [Serializable]
  59. public class WindowPositionList : IXmlSerializable
  60. {
  61. public XmlSchema GetSchema ()
  62. {
  63. return null;
  64. }
  65.  
  66. public void ReadXml (XmlReader reader)
  67. {
  68. reader.ReadStartElement ("WindowPositions");
  69. reader.ReadEndElement ();
  70. }
  71.  
  72. public void WriteXml (XmlWriter writer)
  73. {
  74. writer.WriteStartElement ("WindowPositions");
  75. writer.WriteEndElement ();
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement