Advertisement
Guest User

C# sample program

a guest
Aug 13th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Serialization;
  6. using System.IO;
  7.  
  8. namespace XmlTest
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. bool doArray = true; // set to true to change to an array
  15. Config config = new Config(doArray);
  16.  
  17. XmlSerializer serializer = new XmlSerializer(typeof(Config));
  18.  
  19. // Writing the document requires a TextWriter.
  20. TextWriter writer = new StreamWriter("Xmltest" + ".xml");
  21.  
  22. // Serialize the object, and close the TextWriter.
  23. serializer.Serialize(writer, config);
  24. writer.Close();
  25. }
  26. }
  27.  
  28. [Serializable]
  29. [XmlInclude(typeof(MyDataItem))]
  30. public class Config
  31. {
  32.  
  33. public object tmp;
  34.  
  35. public Config()
  36. {
  37.  
  38. }
  39.  
  40. public Config(bool doArray)
  41. {
  42.  
  43. MyDataItem o = new MyDataItem();
  44. if (doArray)
  45. o.Value = new int[1];
  46. else
  47. o.Value = 0;
  48.  
  49. tmp = o;
  50. }
  51.  
  52.  
  53.  
  54. }
  55.  
  56. [Serializable]
  57. public class MyDataItem
  58. {
  59. public object Value;
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement