当前位置: 首页>>代码示例>>C#>>正文


C# JsonPatchDocument.ApplyUpdatesTo方法代码示例

本文整理汇总了C#中JsonPatchDocument.ApplyUpdatesTo方法的典型用法代码示例。如果您正苦于以下问题:C# JsonPatchDocument.ApplyUpdatesTo方法的具体用法?C# JsonPatchDocument.ApplyUpdatesTo怎么用?C# JsonPatchDocument.ApplyUpdatesTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonPatchDocument的用法示例。


在下文中一共展示了JsonPatchDocument.ApplyUpdatesTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Patch

        public Car Patch(int id, JsonPatchDocument<Car> patchData)
        {
            // TODO: Do some validation and all that fun stuff

            var carTuple = _carsCtx.GetSingle(id);
            if (!carTuple.Item1)
            {
                var response = Request.CreateResponse(HttpStatusCode.NotFound);
                throw new HttpResponseException(response);
            }

            patchData.ApplyUpdatesTo(carTuple.Item2);

            carTuple.Item2.Id = id;
            if (!_carsCtx.TryUpdate(carTuple.Item2))
            {
                var response = Request.CreateResponse(HttpStatusCode.NotFound);
                throw new HttpResponseException(response);
            }

            return carTuple.Item2;
        }
开发者ID:tugberkugurlu,项目名称:ASPNETWebAPISamples,代码行数:22,代码来源:CarsController.cs

示例2: ApplyUpdate_MoveFromPropertyToList_EntityUpdated

        public void ApplyUpdate_MoveFromPropertyToList_EntityUpdated()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument<ComplexEntity>();
            var entity = new ComplexEntity
            {
                Bar = new SimpleEntity
                {
                    Foo = "I am foo"
                },
                Norf = new List<ListEntity>
                {
                    new ListEntity
                    {
                        Foo = new List<string> { "Element One", "Element Two", "Element Three" }
                    }
                }
            };

            //Act
            patchDocument.Move("/Bar/Foo", "/Norf/0/Foo/1");
            patchDocument.ApplyUpdatesTo(entity);

            //Assert
            Assert.IsNull(entity.Bar.Foo);
            Assert.AreEqual(4, entity.Norf[0].Foo.Count);
            Assert.AreEqual("Element One", entity.Norf[0].Foo[0]);
            Assert.AreEqual("I am foo", entity.Norf[0].Foo[1]);
            Assert.AreEqual("Element Two", entity.Norf[0].Foo[2]);
            Assert.AreEqual("Element Three", entity.Norf[0].Foo[3]);
        }
开发者ID:bradodarb,项目名称:JsonPatch,代码行数:31,代码来源:JsonPatchDocumentTests.cs

示例3: ApplyUpdate_MoveListElement_EntityUpdated

        public void ApplyUpdate_MoveListElement_EntityUpdated()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument<ListEntity>();
            var entity = new ListEntity
            {
                Foo = new List<string> { "Element One", "Element Two", "Element Three" }
            };

            //Act
            patchDocument.Move("/Foo/2", "/Foo/1");
            patchDocument.ApplyUpdatesTo(entity);

            //Assert
            Assert.AreEqual(3, entity.Foo.Count);
            Assert.AreEqual("Element One", entity.Foo[0]);
            Assert.AreEqual("Element Three", entity.Foo[1]);
            Assert.AreEqual("Element Two", entity.Foo[2]);
        }
开发者ID:bradodarb,项目名称:JsonPatch,代码行数:19,代码来源:JsonPatchDocumentTests.cs

示例4: ApplyUpdate_MoveOperation_EntityUpdated

        public void ApplyUpdate_MoveOperation_EntityUpdated()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument<SimpleEntity>();
            var entity = new SimpleEntity { Foo = "bar", Baz = "qux" };

            //Act
            patchDocument.Move("Foo", "Baz");
            patchDocument.ApplyUpdatesTo(entity);

            //Assert
            Assert.IsNull(entity.Foo);
            Assert.AreEqual("bar", entity.Baz);
        }
开发者ID:bradodarb,项目名称:JsonPatch,代码行数:14,代码来源:JsonPatchDocumentTests.cs

示例5: ApplyUpdate_ReplaceOperation_EntityUpdated

        public void ApplyUpdate_ReplaceOperation_EntityUpdated()
        {
            //Arrange
            var patchDocument = new JsonPatchDocument<SimpleEntity>();
            var entity = new SimpleEntity { Foo = "bar" };

            //Act
            patchDocument.Replace("Foo", "baz");
            patchDocument.ApplyUpdatesTo(entity);

            //Assert
            Assert.AreEqual("baz", entity.Foo);
        }
开发者ID:bradodarb,项目名称:JsonPatch,代码行数:13,代码来源:JsonPatchDocumentTests.cs


注:本文中的JsonPatchDocument.ApplyUpdatesTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。