From aaefd72c6917a2f497b8883b81116406cd29fc5d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 7 Jan 2022 22:57:12 +0900 Subject: [PATCH] Handle ignored mappings locally in `Detach` configuration --- osu.Game/Beatmaps/BeatmapSetInfo.cs | 3 --- osu.Game/Database/RealmObjectExtensions.cs | 4 +++- osu.Game/Scoring/ScoreInfo.cs | 8 -------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index 1cc6a96f40..f6ca184ea3 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using AutoMapper; using osu.Framework.Testing; using osu.Game.Database; using osu.Game.Extensions; @@ -76,10 +75,8 @@ namespace osu.Game.Beatmaps public bool Equals(IBeatmapSetInfo? other) => other is BeatmapSetInfo b && Equals(b); - [IgnoreMap] IEnumerable IBeatmapSetInfo.Beatmaps => Beatmaps; - [IgnoreMap] IEnumerable IHasNamedFiles.Files => Files; } } diff --git a/osu.Game/Database/RealmObjectExtensions.cs b/osu.Game/Database/RealmObjectExtensions.cs index dfa3076448..9827ca6edd 100644 --- a/osu.Game/Database/RealmObjectExtensions.cs +++ b/osu.Game/Database/RealmObjectExtensions.cs @@ -22,7 +22,9 @@ namespace osu.Game.Database private static readonly IMapper mapper = new MapperConfiguration(c => { c.ShouldMapField = fi => false; - c.ShouldMapProperty = pi => true; + // If we want to limit this further, we can avoid mapping properties with no setter that are not IList<>. + // Takes a bit of effort to determine whether this is the case though, see https://stackoverflow.com/questions/951536/how-do-i-tell-whether-a-type-implements-ilist + c.ShouldMapProperty = pi => pi.GetMethod?.IsPublic == true; c.CreateMap(); c.CreateMap(); diff --git a/osu.Game/Scoring/ScoreInfo.cs b/osu.Game/Scoring/ScoreInfo.cs index c07f4a4f87..65c31951b8 100644 --- a/osu.Game/Scoring/ScoreInfo.cs +++ b/osu.Game/Scoring/ScoreInfo.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using AutoMapper; using Newtonsoft.Json; using osu.Framework.Localisation; using osu.Framework.Testing; @@ -113,16 +112,9 @@ namespace osu.Game.Scoring [MapTo(nameof(Rank))] public int RankInt { get; set; } - [IgnoreMap] IRulesetInfo IScoreInfo.Ruleset => Ruleset; - - [IgnoreMap] IBeatmapInfo IScoreInfo.Beatmap => Beatmap; - - [IgnoreMap] IUser IScoreInfo.User => User; - - [IgnoreMap] IEnumerable IHasNamedFiles.Files => Files; #region Properties required to make things work with existing usages