fork download
  1. using System;
  2. using System.Xml.Serialization;
  3. using System.IO;
  4.  
  5. [Serializable]
  6. public class Config
  7. {
  8. public string UserName { get; set; }
  9. public float SomeFloat { get; set; }
  10.  
  11. public void Write(TextWriter writer)
  12. {
  13. XmlSerializer x = new XmlSerializer(typeof(Config));
  14. x.Serialize(writer, this);
  15. }
  16. public static Config Read(TextReader reader)
  17. {
  18. XmlSerializer x = new XmlSerializer(typeof(Config));
  19. return (Config)x.Deserialize(reader);
  20. }
  21. }
  22.  
  23. public class XMLtest
  24. {
  25. public static void Main()
  26. {
  27. var adminConfig = new Config
  28. {
  29. UserName = "admin",
  30. SomeFloat = 1024
  31. };
  32. adminConfig.Write(Console.Out);
  33. Console.Write("\n\n");
  34. var another = Config.Read(Console.In);
  35. Console.WriteLine($"UserName = {another.UserName}\n"+
  36. $"SomeFloat = {another.SomeFloat}");
  37. }
  38. }
Success #stdin #stdout 0.34s 32940KB
stdin
<?xml version="1.0" encoding="utf-8"?>
<Config xmlns:xsd="http://w...content-available-to-author-only...3.org/2001/XMLSchema" xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance">
  <UserName>default</UserName>
  <SomeFloat>1337</SomeFloat>
</Config>
stdout
<?xml version="1.0" encoding="utf-8"?>
<Config xmlns:xsd="http://w...content-available-to-author-only...3.org/2001/XMLSchema" xmlns:xsi="http://w...content-available-to-author-only...3.org/2001/XMLSchema-instance">
  <UserName>admin</UserName>
  <SomeFloat>1024</SomeFloat>
</Config>

UserName = default
SomeFloat = 1337