-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSetAntonymReferenceChange.cs
More file actions
25 lines (21 loc) · 1.05 KB
/
SetAntonymReferenceChange.cs
File metadata and controls
25 lines (21 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using SIL.Harmony.Changes;
using SIL.Harmony.Entities;
using SIL.Harmony.Sample.Models;
namespace SIL.Harmony.Sample.Changes;
public class SetAntonymReferenceChange(Guid entityId, Guid antonymId, bool setObject = true)
: EditChange<Word>(entityId), ISelfNamedType<SetAntonymReferenceChange>
{
public Guid AntonymId { get; set; } = antonymId;
public bool SetObject { get; set; } = setObject;
public override async ValueTask ApplyChange(Word entity, IChangeContext context)
{
//if the word being referenced was deleted before this change was applied (could happen after a sync)
//then we don't want to apply the change
//if the change was already applied,
//then this reference is removed via Word.RemoveReference after the change which deletes the Antonym, see SnapshotWorker.MarkDeleted
var antonym = await context.GetCurrent<Word>(AntonymId);
if (antonym is null or { DeletedAt: not null }) return;
entity.Antonym = SetObject ? antonym : null;
entity.AntonymId = AntonymId;
}
}