by
30 8
0
7
225k
0
Top 1% !
Popular
Pearl of Wisdom
Tagged
Easy-to-find
Specified
Refined
Popularity: 6574th place
This snippet is Public
.NETFramework4.0
Architecturex86_64
Extension.cs
InputName0customers_Id
InputType0int
LanguageCSharp
LicenseMIT_X11
MethodNameGetCustomerData
OSWindows
OutputTypestring
Windows VersionWindows7

Serializing a C# object to XML

We use a simplified object WSCustomer, since we only want some members of Customer to get serialized.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/669/Serializing-a-C--object-to-XML?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
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; } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus