我的配置文件如下:
{
"Authentication" : {
"Credentials": {
"UserName": "username",
"Password": "password"
},
"Type": "Basic"
},
"Input": {
"Type": "application/xml",
"FileName": "input.xml"
},
"BaseUrl": "http:/baseurl/blahblah",
"DefaultTransformation": "xml"
}
我想知道如何在不为每个嵌套属性创建特定类的情况下生成简单类:
public class Configuration
{
public ConfigurationAuthentication Authentication { get; set; }
}
public class ConfigurationAuthentication
{
public ConfigurationAuthenticationCredentials Credentials { get; set; }
public string Type { get; set; }
}
public class ConfigurationAuthenticationCredentials
{
public string UserName { get; set; }
public string Password { get; set; }
}
等
我曾考虑过使用dynamic
:JsonConvert.DeserializeObject(configurationContent);
,但是我不确定这是最好的选择。