Copy() public method

Copy the value at specified location to the target location. Willr esult in, for example: { "op": "copy", "from": "/a/b/c", "path": "/a/b/e" }
public Copy ( string from, string path ) : JsonPatchDocument
from string source location
path string target location
return JsonPatchDocument
コード例 #1
0
        public void NonGenericPatchDocToGenericMustSerialize()
        {
            // Arrange
            var targetObject = new SimpleObject()
            {
                StringProperty        = "A",
                AnotherStringProperty = "B"
            };

            var patchDocument = new JsonPatchDocument();

            patchDocument.Copy("StringProperty", "AnotherStringProperty");

            var serialized   = JsonConvert.SerializeObject(patchDocument);
            var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument <SimpleObject> >(serialized);

            // Act
            deserialized.ApplyTo(targetObject);

            // Assert
            Assert.Equal("A", targetObject.AnotherStringProperty);
        }
コード例 #2
0
        public void CopyPropertyValue_ToDynamicTestObject_WithCustomNamingStrategy()
        {
            // Arrange
            var contractResolver = new DefaultContractResolver
            {
                NamingStrategy = new TestNamingStrategy()
            };

            dynamic targetObject = new DynamicTestObject();

            targetObject.customStringProperty        = "A";
            targetObject.customAnotherStringProperty = "B";

            var patchDocument = new JsonPatchDocument();

            patchDocument.Copy("StringProperty", "AnotherStringProperty");
            patchDocument.ContractResolver = contractResolver;

            // Act
            patchDocument.ApplyTo(targetObject);

            // Assert
            Assert.Equal("A", targetObject.customAnotherStringProperty);
        }