我正在尝试序列化字典的字典,其中父字典的键为 type enum,子字典的键为 type DateTime。在尝试插入我的收藏时,我遇到了
使用 DictionaryRepresentation.Document 时,键值必须序列化为字符串
我读过讨论enuminto序列化的论坛string,但是根据当前的模型定义,我不确定如何使用此方法。
当前使用的两个字典模型只是该类的实现Dictionary:
指数值
{
public class IndexValues : Dictionary<Index, DateDictionary> { }
}
Run Code Online (Sandbox Code Playgroud)
日期字典
public class DateDictionary : Dictionary<DateTime, double>
{
public double AsOf(DateTime d)
{
DateTime date = d;
while (date >= Keys.Min())
{
if (TryGetValue(date, out var value))
{
return value;
}
date = date.AddDays(-1);
}
throw new Exception($"The dictionary doesn't have a value for any date less than or equal to …Run Code Online (Sandbox Code Playgroud)