class Program
{
static void Main(string[] args)
{
ObjectToXml(new object(), new ResponseZZZ());
Console.ReadLine();
}
public static XmlDocument ObjectToXml<SerializationType>(Object obj, SerializationType MyClass) where SerializationType : class, new()
{
XmlDocument xml = new XmlDocument();
XmlSerializer formatter = new XmlSerializer(typeof(SerializationType));
using (MemoryStream memStm = new MemoryStream())
{
formatter.Serialize(memStm, obj);
memStm.Position = 0;
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (var xtr = XmlReader.Create(memStm, settings))
{
xml = new XmlDocument();
xml.Load(xtr);
}
}
return xml;
}
}
[XmlRoot(ElementName = "response")]
public class ResponseZZZ
{
[XmlElement(ElementName = "txn_id")]
public string txn_id { get; set; }
[XmlElement(ElementName = "result")]
public string Result { get; set; }
[XmlElement(ElementName = "comment")]
public string Comment { get; set; }
}
private void Form1_Load(object sender, EventArgs e)
{
string[] names = { "first", "second", "threes" };
int yPosition = 33;
foreach (var name in names)
{
var checkBox = new CheckBox() { Location = new Point(101, yPosition), Text = name, };
checkBox.Click += (o, args) => { this.Select(name); };
this.Controls.Add(checkBox);
yPosition += 22;
}
}
public void Select(string name)
{
MessageBox.Show(name);
}