Try this
Serialization
means converting the
object
to an
xml
but you have used De-Serialize method.
your code seems that you are try to make the function generic. hope it helps.
using System;
using System.Xml.Serialization;
public class AddressDetails
{
public int HouseNo { get; set; }
public string StreetName { get; set; }
public string City { get; set; }
private string PoAddress { get; set; }
}
public class MyCLass
{
public static string ConvertToXml<T>(object xml)
{
var stringwriter = new System.IO.StringWriter();
var serializer = new XmlSerializer(typeof(T));
serializer.Serialize(stringwriter, xml);
return stringwriter.ToString();
}
static void Main(string[] args)
{
AddressDetails details = new AddressDetails();
details.HouseNo = 4;
details.StreetName = "Rohini";
details.City = "Delhi";
var xmlString = ConvertToXml<AddressDetails>(details);
Console.WriteLine(xmlString);
Console.ReadLine();
}
}