bojan.hrnkas
bojan.hrnkas
Reputation Top 10%
Bojan Hrnkas
1 Snippet  (774th place)
Published
0 Channels
Created
1 Channel
Following
30 points  (1732nd place)
Reputation
Junior Code Generator
Junior Publisher
Junior Team Manager
Junior Popular Coder
Junior Autobiographer
Serious Autobiographer
Senior Autobiographer
Junior Wise Coder

Recent Snippets See all snippets by bojan.hrnkas

public by bojan.hrnkas  225158  0  7  0

Serializing a C# object to XML

We use a simplified object WSCustomer, since we only want some members of Customer to get serialized.
public string GetCustomerData(int customers_Id)
{
    Customer customers = IoC.Resolve<ICustomerService>().GetCustomerById(customers_Id);
    WSCustomer wsCustomer = WSMapping(customers);
    StringBuilder sb = new StringBuilder();
    using (TextWriter tw = new StringWriter(sb))
    {
        XmlSerializer xmlS = new XmlSerializer(typeof(WSCustomer));
        xmlS.Serialize(tw, wsCustomer);
        string serialized = sb.ToString();
        return serialized;
    }
}

;