Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml.Serialization;
- namespace XmlSerializerTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- FirstLevel fl = new FirstLevel();
- fl.UserType = "Administrator";
- fl.Credentials = new SecondLevel()
- {
- Username = "FiftyToo",
- Password = "youwish"
- };
- XmlSerializer xml = new XmlSerializer(typeof(FirstLevel));
- using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
- {
- xml.Serialize(stream, fl);
- textBox1.Text = System.Text.ASCIIEncoding.UTF8.GetString(stream.ToArray());
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml.Serialization;
- namespace XmlSerializerTest
- {
- [Serializable]
- public class FirstLevel
- {
- public string UserType { get; set; }
- public SecondLevel Credentials { get; set; }
- }
- [Serializable]
- public class SecondLevel
- {
- public string Username { get; set; }
- public string Password { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement