Ejemplo n.º 1
0
        internal void Apply(T objectToApplyTo, IObjectAdapter <T> adapter)
        {
            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo);
                break;

            case OperationType.Test:
                throw new NotImplementedException("Test is currently not implemented.");

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        public void Apply(TModel objectToApplyTo, IObjectAdapter <TModel> adapter)
        {
            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo);
                break;

            case OperationType.Test:
                throw new NotSupportedException(Resources.TestOperationNotSupported);

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        public void Apply(object objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException("objectToApplyTo");
            }

            if (adapter == null)
            {
                throw new ArgumentNullException("adapter");
            }

            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;
            }
        }
Ejemplo n.º 4
0
        public void Apply(T objectToApplyTo, IObjectAdapter <T> adapter)
        {
            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo);
                break;

            case OperationType.Test:
                adapter.Test(this, objectToApplyTo);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 5
0
        public IEnumerable <PatchOperationResult> Apply(TModel objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException("objectToApplyTo");
            }

            if (adapter == null)
            {
                throw new ArgumentNullException("adapter");
            }

            switch (OperationType)
            {
            case OperationType.Add:
                return(adapter.Add(this, objectToApplyTo));

            case OperationType.Remove:
                return(adapter.Remove(this, objectToApplyTo));

            case OperationType.Replace:
                return(adapter.Replace(this, objectToApplyTo));

            default:
                throw new InvalidOperationException(string.Format("Patch OperationType type '{0}' is invalid.", OperationType));
            }
        }
Ejemplo n.º 6
0
        public void Apply(object objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException("objectToApplyTo");
            }

            if (adapter == null)
            {
                throw new ArgumentNullException("adapter");
            }

            switch (OperationType)
            {
                case OperationType.Add:
                    adapter.Add(this, objectToApplyTo);
                    break;
                case OperationType.Remove:
                    adapter.Remove(this, objectToApplyTo);
                    break;
                case OperationType.Replace:
                    adapter.Replace(this, objectToApplyTo);
                    break;
            }
        }
Ejemplo n.º 7
0
        public void Apply(object objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException(nameof(objectToApplyTo));
            }

            if (adapter == null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            switch (OperationType)
            {
                case OperationType.Add:
                    adapter.Add(this, objectToApplyTo);
                    break;
                case OperationType.Remove:
                    adapter.Remove(this, objectToApplyTo);
                    break;
                case OperationType.Replace:
                    adapter.Replace(this, objectToApplyTo);
                    break;
                case OperationType.Move:
                    adapter.Move(this, objectToApplyTo);
                    break;
                case OperationType.Copy:
                    adapter.Copy(this, objectToApplyTo);
                    break;
                case OperationType.Test:
                    throw new NotSupportedException(Resources.TestOperationNotSupported);
                default:
                    break;
            }
        }
Ejemplo n.º 8
0
        public void Apply(TModel objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException(nameof(objectToApplyTo));
            }

            if (adapter == null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo);
                break;

            case OperationType.Test:
                if (adapter is IObjectAdapterWithTest adapterWithTest)
                {
                    adapterWithTest.Test(this, objectToApplyTo);
                    break;
                }
                else
                {
                    throw new JsonPatchException(new JsonPatchError(objectToApplyTo, this, Resources.TestOperationNotSupported));
                }

            case OperationType.Invalid:
                throw new JsonPatchException(
                          Resources.FormatInvalidJsonPatchOperation(op), innerException: null);

            default:
                break;
            }
        }
Ejemplo n.º 9
0
        public void Apply(object objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException(nameof(objectToApplyTo));
            }

            if (adapter == null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo);
                break;

            case OperationType.Test:
                if (adapter is IObjectAdapterWithTest adapterWithTest)
                {
                    adapterWithTest.Test(this, objectToApplyTo);
                    break;
                }
                else
                {
                    throw new NotSupportedException(Resources.TestOperationNotSupported);
                }

            default:
                break;
            }
        }
Ejemplo n.º 10
0
        public void Apply(TModel objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException(nameof(objectToApplyTo));
            }

            if (adapter == null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo);
                break;

            case OperationType.Test:
                throw new NotImplementedException("Test is currently not implemented.");

            case OperationType.Invalid:
                throw new JsonPatchException(
                          Resources.FormatInvalidJsonPatchOperation(op), innerException: null);

            default:
                break;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     Applies the operation to the target object using the specified adapter.
        /// </summary>
        /// <param name="objectToApplyTo">The target object.</param>
        /// <param name="adapter">The <see cref="IObjectAdapter" />.</param>
        public void Apply(TModel objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException(nameof(objectToApplyTo));
            }

            if (adapter == null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo, typeof(TModel));
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo, typeof(TModel));
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo, typeof(TModel));
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo, typeof(TModel));
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo, typeof(TModel));
                break;

            case OperationType.Test when adapter is IObjectAdapterWithTest adapterWithTest:
                adapterWithTest.Test(this, objectToApplyTo, typeof(TModel));
                break;

            case OperationType.Test:
                throw new JsonPatchException(new JsonPatchError(objectToApplyTo, this, "The test operation is not supported."));

            case OperationType.Invalid:
                throw new JsonPatchException($"Invalid JsonPatch operation '{Op}'.");
            }
        }
Ejemplo n.º 12
0
        public void Apply(object objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException(nameof(objectToApplyTo));
            }

            if (adapter == null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo);
                break;

            case OperationType.Test:
                adapter.Test(this, objectToApplyTo);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 13
0
        public void Apply(TModel objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new ArgumentNullException(nameof(objectToApplyTo));
            }

            if (adapter == null)
            {
                throw new ArgumentNullException(nameof(adapter));
            }

            switch (OperationType)
            {
            case OperationType.Add:
                adapter.Add(this, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(this, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(this, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(this, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(this, objectToApplyTo);
                break;

            case OperationType.Test:
                throw new JsonPatchException(new JsonPatchError(objectToApplyTo, this, Resources.TestOperationNotSupported));

            default:
                break;
            }
        }
Ejemplo n.º 14
0
        internal static void Apply(this Operation operation, object objectToApplyTo, IObjectAdapter adapter)
        {
            if (objectToApplyTo == null)
            {
                throw new NullReferenceException("objectToApplyTo cannot be null");
            }
            if (adapter == null)
            {
                throw new NullReferenceException("adapter cannot be null");
            }

            switch (operation.OperationType)
            {
            case OperationType.Add:
                adapter.Add(operation, objectToApplyTo);
                break;

            case OperationType.Remove:
                adapter.Remove(operation, objectToApplyTo);
                break;

            case OperationType.Replace:
                adapter.Replace(operation, objectToApplyTo);
                break;

            case OperationType.Move:
                adapter.Move(operation, objectToApplyTo);
                break;

            case OperationType.Copy:
                adapter.Copy(operation, objectToApplyTo);
                break;

            case OperationType.Test:
                throw new NotImplementedException("Test is currently not implemented.");

            default:
                break;
            }
        }