public INCMBFieldOperation MergeWithPrevious(INCMBFieldOperation previous)
        {
            if (previous == null)
            {
                return(this);
            }

            if ((previous is NCMBDeleteOperation))
            {
                return(new NCMBSetOperation(this.amount));
            }

            if ((previous is NCMBSetOperation))
            {
                object value = ((NCMBSetOperation)previous).getValue();
                if (value is string || value == null)
                {
                    throw new  InvalidOperationException("You cannot increment a non-number.");
                }
                return(new NCMBSetOperation(NCMBObject._addNumbers(value, this.amount)));
            }

            if ((previous is NCMBIncrementOperation))
            {
                object oldAmount = (((NCMBIncrementOperation)previous).amount);
                return(new NCMBIncrementOperation(NCMBObject._addNumbers(oldAmount, this.amount)));
            }
            throw new  InvalidOperationException("Operation is invalid after previous operation.");
        }
 public object Apply(object oldValue, NCMBObject obj, string key)
 {
     if (oldValue == null)
     {
         return(this.amount);
     }
     if (oldValue is string || oldValue == null)
     {
         throw new  InvalidOperationException("You cannot increment a non-number.");
     }
     return(NCMBObject._addNumbers(oldValue, this.amount));
 }