I'm trying to (de)serialize following YAML using YamlDotNet or SharpYaml:
network:
IF1:
gateway4: 10.1.0.1
addresses:
- 10.1.0.10/24
- 10.1.0.20/24
IF2:
gateway4: 10.2.0.1
addresses:
- 10.2.0.10/24
- 10.2.0.20/24
I've have this C# class:
public class NetworkConfig
{
public class Network
{
//[ClassName]
public string NetworkName { get; set; }
public List<Interface> Interfaces;
public class Interface
{
//[ClassName]
public string InterfaceName { get; set; }
public string gateway4;
public List<String> addresses;
}
}
}
Instantiation:
var NetworkCfg = new NetworkConfig();
var Network = new NetworkConfig.Network();
Network.NetworkName = "network";
Network.Interfaces = new List<NetworkConfig.Network.Interface> {
new NetworkConfig.Network.Interface
{
InterfaceName = "IF1",
gateway4 = "10.1.0.1",
addresses = new List<string> { "10.1.0.10/24", "10.1.0.20/24"}
},
new NetworkConfig.Network.Interface
{
InterfaceName = "IF2",
gateway4 = "10.2.0.1",
addresses = new List<string> { "10.2.0.10/24", "10.2.0.20/24"}
}
};
How do I name the key/class Network
and Interface
?
One solution I could think of would be an attribute for a property, something like [ClassName]
but I haven't been able to find one.