1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 01:27:29 +08:00

Add back PerformRead return safety by checking IsManaged status of returned data

This commit is contained in:
Dean Herbert 2022-01-13 13:14:44 +09:00
parent 085893c9b4
commit 7baff18764

View File

@ -61,15 +61,18 @@ namespace osu.Game.Database
/// <param name="perform">The action to perform.</param>
public TReturn PerformRead<TReturn>(Func<T, TReturn> perform)
{
// TODO: this is weird and kinda wrong... unmanaged objects should be allowed?
// if (typeof(RealmObjectBase).IsAssignableFrom(typeof(TReturn)))
// throw new InvalidOperationException(@$"Realm live objects should not exit the scope of {nameof(PerformRead)}.");
if (!IsManaged)
return perform(data);
using (var realm = realmFactory.CreateContext())
return perform(realm.Find<T>(ID));
{
var returnData = perform(realm.Find<T>(ID));
if (returnData is RealmObjectBase realmObject && realmObject.IsManaged)
throw new InvalidOperationException(@$"Managed realm objects should not exit the scope of {nameof(PerformRead)}.");
return returnData;
}
}
/// <summary>