People have asked this question before on how to Serialize/Deserialize A Dictionary with custom Key using Newtonsoft . The documentation says:
When serializing a dictionary, the keys of the dictionary are converted to strings and used as the JSON object property names. The string written for a key can be customized by either overriding ToString() for the key type or by implementing a TypeConverter. A TypeConverter will also support converting a custom string back again when deserializing a dictionary.
Everyone has posted answers on TypeConverter but no where do I see an example of overriding ToString on my custom type.
Has anyone successfully done that?
public class MyType
{
public string Name {get;set;}
public string ID {get;set;}
public string Location {get;set}
public override ToString()
{
// what to do here??
}
}
public class MyClass
{
public Dictionary<MyType, string> CustomKeyDictionary {get;set;}
}