// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using Realms; #nullable enable namespace osu.Game.Database { /// /// Provides a method of working with unmanaged realm objects. /// Usually used for testing purposes where the instance is never required to be managed. /// /// The underlying object type. public class RealmLiveUnmanaged : ILive where T : RealmObjectBase, IHasGuidPrimaryKey { /// /// Construct a new instance of live realm data. /// /// The realm data. public RealmLiveUnmanaged(T data) { Value = data; } public bool Equals(ILive? other) => ID == other?.ID; public override string ToString() => Value.ToString(); public Guid ID => Value.ID; public void PerformRead(Action perform) => perform(Value); public TReturn PerformRead(Func perform) => perform(Value); public void PerformWrite(Action perform) => throw new InvalidOperationException(@"Can't perform writes on a non-managed underlying value"); public bool IsManaged => false; /// /// The original live data used to create this instance. /// public T Value { get; } } }