public static Config LoadFromString (string content, string root, bool expandRoot)
{
var config = JsonConvert.DeserializeObject<Config> (content);
config.monoRoot = root == null ? null : Path.GetFullPath (root);
if (String.IsNullOrWhiteSpace (config.Name))
throw new InvalidDataException ("Configuration does not have a `Name`.");
if (config.NoMono) {
if (!(config.MonoOptions == null || config.MonoOptions.Length == 0)) {
throw new Exception ("config error");
}
if (!(config.MonoEnvironmentVariables == null || config.MonoEnvironmentVariables.Count == 0)) {
throw new Exception ("config error");
}
if (!(config.UnsavedMonoEnvironmentVariables == null || config.UnsavedMonoEnvironmentVariables.Count == 0)) {
throw new Exception ("config error");
}
}
if (String.IsNullOrWhiteSpace (config.Mono)) {
config.Mono = String.Empty;
} else if (expandRoot && root != null) {
config.Mono = config.Mono.Replace (rootVarString, config.monoRoot);
} else if (expandRoot && config.Mono.Contains (rootVarString)) {
throw new InvalidDataException ("Configuration requires a root directory.");
}
if (config.Count < 1)
config.Count = 10;
if (config.MonoOptions == null)
config.MonoOptions = new string[0];
if (config.MonoEnvironmentVariables == null)
config.MonoEnvironmentVariables = new Dictionary<string, string> ();
if (config.UnsavedMonoEnvironmentVariables == null)
config.UnsavedMonoEnvironmentVariables = new Dictionary<string, string> ();
return config;
}