I am working with a 3rd party who has an xml structure for multiple different requests.
Each request has a common header structure and then some specific footer data.
Unfortunately, the header and footer sections are not wrapped within their own element tags and this is something that I can't change.
Some sample contrived requests are shown below:
Sample Request 1
<?xml version="1.0" encoding="UTF - 8" standalone="yes"?>
<Request>
<RequestType>1</RequestType>
<User>User01</User>
<id>1234</id>
<Name>John</Name>
<Age>20</Age>
</Request>
Sample Request 2
<?xml version="1.0" encoding="UTF - 8" standalone="yes"?>
<Request>
<RequestType>2</RequestType>
<User>User02</User>
<id>1235</id>
<School>The School</School>
<Teacher>Mrs Smith</Teacher>
</Request>
Sample Request 3
<?xml version="1.0" encoding="UTF - 8" standalone="yes"?>
<Request>
<RequestType>3</RequestType>
<User>User01</User>
<id>223</id>
<Work>The Office</Word>
<Boss>Mr White</Boss>
<Phone>1234567</Phone>
<Payday>Friday</Payday>
</Request>
You can see that each request has a RequestType, User and id.
My question relates to writing C# code that will encapsulate this Xml for serialization.
To me, it seems wrong to have each of my C# classes having the repeated header (RequestType, User and id) data.
I have tried using generics (see sample code below) but that leads to my question.
Question: How can I serialize my generic object Footer so that it is not wrapped within "root" Footer element?
[System.Xml.Serialization.XmlRoot("Request")]
public class GenericRequest<typeT>
{
public GenericRequest()
{
}
public int RequestType { get; set; }
public string User { get; set; }
public int id { get; set; }
public typeT Footer { get; set; }
}