mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 12:47:18 +08:00
Add helper function to get realm class names rather than hard-coding each time
This commit is contained in:
parent
c2c567f5f5
commit
7772a97cf7
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Development;
|
using osu.Framework.Development;
|
||||||
@ -167,7 +168,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
void convertOnlineIDs<T>() where T : RealmObject
|
void convertOnlineIDs<T>() where T : RealmObject
|
||||||
{
|
{
|
||||||
string className = typeof(T).Name.Replace(@"Realm", string.Empty);
|
string className = getMappedOrOriginalName(typeof(T));
|
||||||
|
|
||||||
// version was not bumped when the beatmap/ruleset models were added
|
// version was not bumped when the beatmap/ruleset models were added
|
||||||
// therefore we must manually check for their presence to avoid throwing on the `DynamicApi` calls.
|
// therefore we must manually check for their presence to avoid throwing on the `DynamicApi` calls.
|
||||||
@ -208,9 +209,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
case 9:
|
case 9:
|
||||||
// Pretty pointless to do this as beatmaps aren't really loaded via realm yet, but oh well.
|
// Pretty pointless to do this as beatmaps aren't really loaded via realm yet, but oh well.
|
||||||
string className = nameof(RealmBeatmapMetadata).Replace(@"Realm", string.Empty);
|
var oldItems = migration.OldRealm.DynamicApi.All(getMappedOrOriginalName(typeof(RealmBeatmapMetadata)));
|
||||||
|
|
||||||
var oldItems = migration.OldRealm.DynamicApi.All(className);
|
|
||||||
var newItems = migration.NewRealm.All<RealmBeatmapMetadata>();
|
var newItems = migration.NewRealm.All<RealmBeatmapMetadata>();
|
||||||
|
|
||||||
int itemCount = newItems.Count();
|
int itemCount = newItems.Count();
|
||||||
@ -285,6 +284,9 @@ namespace osu.Game.Database
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/realm/realm-dotnet/blob/32f4ebcc88b3e80a3b254412665340cd9f3bd6b5/Realm/Realm/Extensions/ReflectionExtensions.cs#L46
|
||||||
|
private static string getMappedOrOriginalName(MemberInfo member) => member.GetCustomAttribute<MapToAttribute>()?.Mapping ?? member.Name;
|
||||||
|
|
||||||
private bool isDisposed;
|
private bool isDisposed;
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user