Skip to content

Commit

Permalink
add GetCurrent<T> to ChangeContext
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Oct 11, 2024
1 parent a63c3ab commit 7d81ade
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/SIL.Harmony/Changes/ChangeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ internal ChangeContext(Commit commit, SnapshotWorker worker, CrdtConfig crdtConf

public Commit Commit { get; }
public async ValueTask<ObjectSnapshot?> GetSnapshot(Guid entityId) => await _worker.GetSnapshot(entityId);
public async ValueTask<T?> GetCurrent<T>(Guid entityId) where T : class
{
var snapshot = await GetSnapshot(entityId);
if (snapshot is null) return null;
return (T) snapshot.Entity.DbObject;
}

public async ValueTask<bool> IsObjectDeleted(Guid entityId) => (await GetSnapshot(entityId))?.EntityIsDeleted ?? true;
internal IObjectBase Adapt(object obj) => _crdtConfig.ObjectTypeListBuilder.AdapterProvider.Adapt(obj);
Expand Down

0 comments on commit 7d81ade

Please sign in to comment.