I have a file named config.json. Here's its contents:
{
dataSources:
[
"http://www.blahblah.com/blah",
"http://www.blahblah.com/blah2",
...
],
skills:
[
{
"name": "foobaris",
"regex": "pattern"
},
...
]
}
I want to create a Config
object out of this data as easily and succinctly as possible. Config
is defined as:
public class Config
{
public IEnumerable<Uri> DataSources { get; set; }
public IEnumerable<KeyValuePair<string, Regex>> Skills { get; set; }
}
What's the easiest route?
Because Config.DataSources
is Uri
s, and .Skills
has Regex
s, I currently have to derserialize (i.e. RawConfig rawConfig = new JavaScriptSerializer().Deserialize<RawConfig>(configFileContents)
) the config file into this struct first:
public struct RawConfig
{
public IEnumerable<string> DataSources { get; set; }
public IEnumerable<RawConfigSkill> Skills { get; set; }
}
public struct RawConfigSkill
{
public string Name { get; set; }
public string Regex { get; set; }
}
...Then convert that struct into a Config
(e.g. new Config(rawConfig)
).
Can I void this?