I have a method to return as instance of a class to XML. Unfortunately, no XML is being returned.
Below is an example of trying to convert a simple Country Class to XML:
Country Class
public class Country : XmlMethods<Country>
{
public readonly int Id;
public readonly string Code;
public readonly string Name;
private Country()
{
}
private Country(int id, string code, string name)
{
Id = id;
Code = code;
Name = name;
}
public static Country Load(int countryId)
{
DataRow dr = //Row From Database
return new Country(
(int)dr["ISOCountryID"],
(string)dr["ISOCode"],
(string)dr["ISOCountry"]);
}
Inhertited Class
public class XmlMethods<T> : BaseClass
{
public XElement ToXElement()
{
using (var memoryStream = new MemoryStream())
{
using (TextWriter streamWriter = new StreamWriter(memoryStream))
{
var xmlSerializer = new XmlSerializer(typeof (T));
xmlSerializer.Serialize(streamWriter, this);
return XElement.Parse(Encoding.ASCII.GetString(memoryStream.ToArray()));
}
}
}
}
Test Method
public void LoadCountry()
{
lbl.Text = "***" + Country.Load(1).ToXElement().ToString() + "***";
}
There are no errors at runtime. All I get from my label is '******'
Any help would be greatly appreciated. Thanks.