Advertisement
Guest User

Untitled

a guest
May 1st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. using System.Xml.Serialization;
  11.  
  12. namespace XmlSerializerTest
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void button1_Click(object sender, EventArgs e)
  22. {
  23. FirstLevel fl = new FirstLevel();
  24. fl.UserType = "Administrator";
  25. fl.Credentials = new SecondLevel()
  26. {
  27. Username = "FiftyToo",
  28. Password = "youwish"
  29. };
  30. XmlSerializer xml = new XmlSerializer(typeof(FirstLevel));
  31. using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
  32. {
  33. xml.Serialize(stream, fl);
  34. textBox1.Text = System.Text.ASCIIEncoding.UTF8.GetString(stream.ToArray());
  35. }
  36. }
  37. }
  38.  
  39.  
  40.  
  41.  
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. using System;
  56. using System.Collections.Generic;
  57. using System.Linq;
  58. using System.Text;
  59.  
  60. using System.Xml.Serialization;
  61.  
  62. namespace XmlSerializerTest
  63. {
  64. [Serializable]
  65. public class FirstLevel
  66. {
  67. public string UserType { get; set; }
  68. public SecondLevel Credentials { get; set; }
  69. }
  70.  
  71. [Serializable]
  72. public class SecondLevel
  73. {
  74. public string Username { get; set; }
  75. public string Password { get; set; }
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement