I’m creating XML file which will hold couple of values regarding TCP Connection (IP (string), PORT (int), RetryCount (int), StartAutomatically (bool) and so on. There will be a number of TcpConnections defined like that (unknown to me).
What i thought is to create some kind of object called TcpConnectionHolder which i could create dynamically (one per tcp connection) that would hold all related fields so i could easily load all tcp connections from xml to that dynamic object and that i could later on reuse those fields, or update them from code when necessary.
My questions are:
- How do I create such object with multiple fields (example with more then one Value -> Data would be nice)
- How do I assign multiple values to one connection – (preferably both setting all values at once and one by one would be nice).
- How do I read it?
It looks like you just need one class (
TcpConnection) with properties for the IP address, port, retry count etc.I’d suggest some kind of structure like this:
(Alternatively, have a static factory method to extract the values from an XElement, and a constructor just taking the “raw” values.)
Then to store multiple values, just use a
List<TcpConnection>.This is neater than a single object storing multiple IP addresses, multiple retry counts etc.