Пример #1
0
        /// <summary>
        /// Patches the specified object using Json.net.
        /// </summary>
        /// <param name="original">The original object to patch.</param>
        /// <param name="afterPatch">The after patch action.</param>
        /// <returns>IServiceResponse{T}.</returns>
        public virtual IServiceResponse <T> Patch(T original, PatchedAction <T> afterPatch)
        {
            JsonConvert.PopulateObject(JsonRepresentation, original);

            if (OnPatchedHandler != null)
            {
                OnPatchedHandler.Invoke(original);
            }

            if (afterPatch != null)
            {
                afterPatch(original);
            }

            return(new DataResponse <T>(original));
        }
Пример #2
0
        /// <summary>
        /// Patches the specified object using Json.net.
        /// </summary>
        /// <param name="original">The original object to patch.</param>
        /// <param name="afterPatch">The after patch action.</param>
        /// <param name="settings">Json serializer settings for use</param>
        /// <returns>IServiceResponse{T}.</returns>
        public virtual IServiceResponse <T> Patch(T original, ClonedPatchedAction <T> afterPatch, JsonSerializerSettings settings = null)
        {
            T clone = null;

            if (afterPatch != null)
            {
                clone = original.Copy();
            }

            JsonConvert.PopulateObject(JsonRepresentation, original, settings ?? new JsonSerializerSettings());

            if (OnPatchedHandler != null)
            {
                OnPatchedHandler.Invoke(original);
            }

            if (afterPatch != null)
            {
                afterPatch(clone, original);
            }

            return(new DataResponse <T>(original));
        }