我在 DynamoDB 中保存用户配置文件,并使用属性将 .net 类型转换为 dynamo 条目
所以这是我正在使用的转换器:
public class DictRoomClassHouseInfoConverter : IPropertyConverter
{
...
public DynamoDBEntry ToEntry(object value)
{
var dictionary = value as Dictionary<RoomClass, HouseInfo>;
if (dictionary == null)
{
throw new ArgumentException("Invalid type");
}
var entry = new PrimitiveList();
foreach (var kvp in dictionary)
{
entry.Add(new Primitive { Value = string.Format("{0}|{1}|{2}", (int)kvp.Key, kvp.Value.House, kvp.Value.TimesSold) });
}
return entry;
}
}
现在的问题是,当 Dictionary 为空并且PrimitiveList
返回一个空时ToEntry
,此 Dictionary 的更改将不会被保存
所以如果我做类似的事情:
var profile = GetProfile(id);
//profile.DictProp has 3 items;
profile.DictProp.Clear();
//profile.DictProp has 0 items;
SaveProfile(profile);
var p = GetProfile(id);
//profile.DictProp has 3 items;