本文整理汇总了C#中JsonPatchDocument.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# JsonPatchDocument.Copy方法的具体用法?C# JsonPatchDocument.Copy怎么用?C# JsonPatchDocument.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonPatchDocument
的用法示例。
在下文中一共展示了JsonPatchDocument.Copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyFromListToEndOfList
public void CopyFromListToEndOfList()
{
dynamic doc = new ExpandoObject();
doc.IntegerList = new List<int>() { 1, 2, 3 };
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Copy("IntegerList/0", "IntegerList/-");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal(new List<int>() { 1, 2, 3, 1 }, doc.IntegerList);
}
示例2: Copy
public void Copy()
{
dynamic doc = new ExpandoObject();
doc.StringProperty = "A";
doc.AnotherStringProperty = "B";
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Copy("StringProperty", "AnotherStringProperty");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal("A", doc.AnotherStringProperty);
}
示例3: NonGenericPatchDocToGenericMustSerialize
public void NonGenericPatchDocToGenericMustSerialize()
{
var doc = new SimpleDTO()
{
StringProperty = "A",
AnotherStringProperty = "B"
};
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Copy("StringProperty", "AnotherStringProperty");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal("A", doc.AnotherStringProperty);
}
示例4: CopyFromListToNonList
public void CopyFromListToNonList()
{
var doc = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Copy("IntegerList/0", "IntegerValue");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal(1, doc.IntegerValue);
}
示例5: Copy
public void Copy()
{
var doc = new SimpleDTO()
{
StringProperty = "A",
AnotherStringProperty = "B"
};
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Copy("StringProperty", "AnotherStringProperty");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal("A", doc.AnotherStringProperty);
}
示例6: CopyFromListToNonList
public void CopyFromListToNonList()
{
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
}
};
// create patch
JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Copy<int>(o => o.SimpleDTO.IntegerList, 0, o => o.SimpleDTO.IntegerValue);
patchDoc.ApplyTo(doc);
Assert.Equal(1, doc.SimpleDTO.IntegerValue);
}
示例7: Copy
public void Copy()
{
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
StringProperty = "A",
AnotherStringProperty = "B"
}
};
// create patch
JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Copy<string>(o => o.SimpleDTO.StringProperty, o => o.SimpleDTO.AnotherStringProperty);
patchDoc.ApplyTo(doc);
Assert.Equal("A", doc.SimpleDTO.AnotherStringProperty);
}
示例8: CopyWithSerialization
public void CopyWithSerialization()
{
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
StringProperty = "A",
AnotherStringProperty = "B"
}
};
// create patch
JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Copy<string>(o => o.SimpleDTO.StringProperty, o => o.SimpleDTO.AnotherStringProperty);
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal("A", doc.SimpleDTO.AnotherStringProperty);
}
示例9: CopyFromNonListToListWithSerialization
public void CopyFromNonListToListWithSerialization()
{
// Arrange
var doc = new SimpleDTO()
{
IntegerValue = 5,
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTO>();
patchDoc.Copy<int>(o => o.IntegerValue, o => o.IntegerList, 0);
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
// Act
deserialized.ApplyTo(doc);
// Assert
Assert.Equal(new List<int>() { 5, 1, 2, 3 }, doc.IntegerList);
}
示例10: CopyToEndOfList
public void CopyToEndOfList()
{
// Arrange
var doc = new SimpleDTO()
{
IntegerValue = 5,
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTO>();
patchDoc.Copy<int>(o => o.IntegerValue, o => o.IntegerList);
// Act
patchDoc.ApplyTo(doc);
// Assert
Assert.Equal(new List<int>() { 1, 2, 3, 5 }, doc.IntegerList);
}
示例11: CopyWithSerialization
public void CopyWithSerialization()
{
// Arrange
var doc = new SimpleDTO()
{
StringProperty = "A",
AnotherStringProperty = "B"
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTO>();
patchDoc.Copy<string>(o => o.StringProperty, o => o.AnotherStringProperty);
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
// Act
deserialized.ApplyTo(doc);
// Assert
Assert.Equal("A", doc.AnotherStringProperty);
}
示例12: CopyFromListToNonList
public void CopyFromListToNonList()
{
// Arrange
var doc = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTO>();
patchDoc.Copy<int>(o => o.IntegerList, 0, o => o.IntegerValue);
// Act
patchDoc.ApplyTo(doc);
// Assert
Assert.Equal(1, doc.IntegerValue);
}
示例13: CopyFromNonListToList
public void CopyFromNonListToList()
{
// Arrange
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
IntegerValue = 5,
IntegerList = new List<int>() { 1, 2, 3 }
}
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Copy<int>(o => o.SimpleDTO.IntegerValue, o => o.SimpleDTO.IntegerList, 0);
// Act
patchDoc.ApplyTo(doc);
// Assert
Assert.Equal(new List<int>() { 5, 1, 2, 3 }, doc.SimpleDTO.IntegerList);
}
示例14: Copy
public void Copy()
{
// Arrange
var doc = new SimpleDTO()
{
StringProperty = "A",
AnotherStringProperty = "B"
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTO>();
patchDoc.Copy<string>(o => o.StringProperty, o => o.AnotherStringProperty);
// Act
patchDoc.ApplyTo(doc);
// Assert
Assert.Equal("A", doc.AnotherStringProperty);
}
示例15: CopyToEndOfList
public void CopyToEndOfList()
{
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
IntegerValue = 5,
IntegerList = new List<int>() { 1, 2, 3 }
}
};
// create patch
JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Copy<int>(o => o.SimpleDTO.IntegerValue, o => o.SimpleDTO.IntegerList);
patchDoc.ApplyTo(doc);
Assert.Equal(new List<int>() { 1, 2, 3, 5 }, doc.SimpleDTO.IntegerList);
}