In this previously answered question, I found how to declare a class that could be serializable and I'm currently mimicking it for my own purposes. I have a further question in that, how would I instantiate the 'Adressess' class and assign parameters to it? Specifically, I'm unsure how to tie data to the 'MainAddress' class, and have it tied to the overall 'Adressess' class. I'm sort of a beginner to object oriented programming.
Here's the class I'm working with:
[XmlRoot("Adressess")]
public class Adressess
{
[XmlElement(ElementName = "MainAddress")]
public MainAddress Main { get; set; }
[XmlElement(ElementName = "AdditionalAddress")]
public List<AdditionalAddress> AdditionalAddresses { get; set; }
}
[XmlRoot("MainAddress")]
public class MainAddress
{
public string Country { get; set; }
public string City { get; set; }
}
[XmlRoot("AdditionalAddress")]
public class AdditionalAddress
{
public string Country { get; set; }
public string City { get; set; }
}
I basically just want to test that I can make an XML file, but I don't know how to assign data to this class before serializing it.
---EDIT---
Thank you DStanley for the quick reply! I was able to build out my approach and generate the XML file I was hoping for. And thank you Mark S for the descriptive answer! I've seen your type of approach before but now it makes sense in my context. I'm going to try and build out your version for it seems much more stable and flexible.
MainAddressandAdditionalAddress?