Add helper method for detaching lists from realm

This commit is contained in:
Dean Herbert 2021-01-11 19:46:51 +09:00
parent d810af82ec
commit fc55d67c66
1 changed files with 11 additions and 0 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using AutoMapper;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
@ -39,6 +40,16 @@ public static class RealmExtensions
c.CreateMap<RulesetInfo, RulesetInfo>();
}).CreateMapper();
public static List<T> Detach<T>(this List<T> items) where T : RealmObject
{
var list = new List<T>();
foreach (var obj in items)
list.Add(obj.Detach());
return list;
}
public static T Detach<T>(this T obj) where T : RealmObject
{
if (!obj.IsManaged)