我需要修补一个字典的值与另一个动态添加新键。我需要保存新密钥并替换现有密钥才能完成补丁功能。必须有我无法访问的现有映射。或者我应该写什么映射配置文件?
[Test]
public void DictionaryMapping()
{
// Arrange
var write = new Dictionary<string, object>
{
{ "Key1", 100 },
{ "Key2", true }
};
var patch = new Dictionary<string, object>
{
{ "Key2", false },
{ "Key3", "Additional"}
};
// Act
Mapper.Map(patch, write);
// Assert
Assert.That(write["Key1"], Is.EqualTo(100));
Assert.That(write["Key2"], Is.EqualTo(false));
Assert.That(write["Key3"], Is.EqualTo("Additional"));
}