This is the code:
public class ParameterDictionary : Dictionary<HydroObjectIdentifier, string>
{
public void WriteToJson(string jsonFilePath)
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(this, formatting: Newtonsoft.Json.Formatting.Indented);
System.IO.File.WriteAllText(jsonFilePath, json);
}
}
public struct HydroObjectIdentifier
{
public string Name { get; set; }
public string TypeName { get; set; }
public HydroObjectIdentifier(string name, string typeName)
{
this.Name = name;
this.TypeName = typeName;
}
}
...and this is the Json result. Notice that it shows the class name RSEngine.HydroObjectIdentifier
instead of its parameters, which was not intended in my code.
{
"RSEngine.HydroObjectIdentifier": [
{
"myString"
},
...
As explained in the comments, the intended behavior is to write Name and TypeName into the json, instead of the name of the class.