csharp-sdk-upm/Storage/Internal/Operation/LCRemoveRelationOperation.cs

43 lines
1.4 KiB
C#
Raw Normal View History

2020-02-19 18:50:51 +08:00
using System;
2020-02-20 12:44:33 +08:00
using System.Collections;
using System.Collections.Generic;
using LeanCloud.Storage.Internal.Codec;
2020-02-19 18:50:51 +08:00
namespace LeanCloud.Storage.Internal.Operation {
2020-02-20 12:44:33 +08:00
internal class LCRemoveRelationOperation : ILCOperation {
List<LCObject> valueList;
internal LCRemoveRelationOperation(LCObject obj) {
valueList = new List<LCObject> { 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() {
2020-02-20 12:44:33 +08:00
return new Dictionary<string, object> {
{ "__op", "RemoveRelation" },
{ "objects", LCEncoder.Encode(valueList) }
};
}
public object Apply(object oldValue, string key) {
LCRelation<LCObject> relation = new LCRelation<LCObject>();
relation.TargetClass = valueList[0].ClassName;
2020-02-20 12:44:33 +08:00
return relation;
}
public IEnumerable GetNewObjectList() {
return null;
2020-02-19 18:50:51 +08:00
}
}
}