using System; using System.Collections; using System.Collections.Generic; using LeanCloud.Storage.Internal.Codec; namespace LeanCloud.Storage.Internal.Operation { internal class LCRemoveRelationOperation : ILCOperation { List valueList; internal LCRemoveRelationOperation(LCObject obj) { valueList = new List { obj }; } public ILCOperation MergeWithPrevious(ILCOperation previousOp) { if (previousOp is LCSetOperation || previousOp is LCDeleteOperation) { return previousOp; } if (previousOp is LCRemoveRelationOperation removeRelationOp) { valueList.AddRange(removeRelationOp.valueList); return this; } throw new ArgumentException("Operation is invalid after previous operation."); } public object Encode() { return new Dictionary { { "__op", "RemoveRelation" }, { "objects", LCEncoder.Encode(valueList) } }; } public object Apply(object oldValue, string key) { LCRelation relation = new LCRelation(); relation.TargetClass = valueList[0].ClassName; return relation; } public IEnumerable GetNewObjectList() { return null; } } }