From 7772a97cf72aeb89470028b2fa479264b2bdafbc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 5 Nov 2021 17:01:00 +0900 Subject: [PATCH] Add helper function to get realm class names rather than hard-coding each time --- osu.Game/Database/RealmContextFactory.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/osu.Game/Database/RealmContextFactory.cs b/osu.Game/Database/RealmContextFactory.cs index be2cf8ff4e..eb8b190975 100644 --- a/osu.Game/Database/RealmContextFactory.cs +++ b/osu.Game/Database/RealmContextFactory.cs @@ -3,6 +3,7 @@ using System; using System.Linq; +using System.Reflection; using System.Threading; using osu.Framework.Allocation; using osu.Framework.Development; @@ -167,7 +168,7 @@ namespace osu.Game.Database void convertOnlineIDs() 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 // 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: // 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(className); + var oldItems = migration.OldRealm.DynamicApi.All(getMappedOrOriginalName(typeof(RealmBeatmapMetadata))); var newItems = migration.NewRealm.All(); 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()?.Mapping ?? member.Name; + private bool isDisposed; public void Dispose()