Created
November 25, 2019 11:55
-
-
Save mgravell/bd817bebd0f4a3d52c5edf0bb4f0fcf8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Xml.Serialization; | |
public class EnquiryResponseInfo | |
{ | |
public string EnquiryId { get; set; } | |
public EnquiryViewModel Enquiry { get; set; } | |
} | |
public class EnquiryViewModel | |
{ | |
public int Whatever { get; set; } | |
} | |
static class P | |
{ | |
static void Main() | |
{ | |
var ser = new XmlSerializer(typeof(EnquiryResponseInfo)); | |
ser.Serialize(Console.Out, new EnquiryResponseInfo { | |
Enquiry = null, EnquiryId = "abc" }); | |
/* output: | |
<?xml version="1.0" encoding="ibm850"?> | |
<EnquiryResponseInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<EnquiryId>abc</EnquiryId> | |
</EnquiryResponseInfo> | |
*/ | |
Console.WriteLine(); | |
Console.WriteLine(); | |
ser.Serialize(Console.Out, new EnquiryResponseInfo { | |
Enquiry = new EnquiryViewModel { Whatever = 123 }, EnquiryId = "abc" }); | |
/* output: | |
<?xml version="1.0" encoding="ibm850"?> | |
<EnquiryResponseInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<EnquiryId>abc</EnquiryId> | |
<Enquiry> | |
<Whatever>123</Whatever> | |
</Enquiry> | |
</EnquiryResponseInfo> | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment