在没有为嵌套属性重新定义大量类的情况下拥有其他配置对象的更好方法?

时间:2018-08-01 06:24:46

标签: .net json json-deserialization

我的配置文件如下:

{
  "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; }
}

我曾考虑过使用dynamicJsonConvert.DeserializeObject(configurationContent);,但是我不确定这是最好的选择。

0 个答案:

没有答案