I need inputs to convert dynamic xml to a specific C # object model
My xml sample looks like this:
<?xml version="1.0" encoding="utf-8" ?> <Persons> <Person> <Id>10</Id> <FirstName> Dino </FirstName> <LastName> Esposito </LastName> <Addresses> <Address> <AddressType>BillTo</AddressType> <Street1></Street1> <Street2></Street2> <Street3></Street3> <City>Moscow</City> </Address> <Address> <AddressType>ShipTo</AddressType> <Street1></Street1> <Street2></Street2> <Street3></Street3> <City>Moscow</City> </Address> <Address> <AddressType>Contact</AddressType> <Street1></Street1> <Street2></Street2> <Street3></Street3> <City>Moscow</City> </Address> </Addresses> </Person> </Persons>
I expect the values ββof this xml to be converted to a C # object at runtime. I would like an object similar to the following to be defined: My expected C # class object is as follows:
public class Person { public int Id { get; set; } public String FirstName { get; set; } public String LastName { get; set; } public IList<Address> Addresses { get; set; } } public class Address { public string AddressType { get; set; } public string Street1 { get; set; } public string Street2 { get; set; } public string Street3 { get; set; } public string City { get; set; } }
I went through dynamic and ExpandoObject in C # 4.0, this approach allows me to dynamically retrieve values ββusing keys. I do not know how I can fill them in my datamodel.
Note. . I do not want to determine the structure of this class model, it is constantly changing over time. I am looking for a solution that allows me to get values ββsuch as DynamicObject.Addresses.Address [0] .City.
Please provide your details.
source share