1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-22 21:00:33 +08:00

BASE_DERIVED -> BASE_TYPE_MAPPING

This commit is contained in:
Salman Ahmed 2021-11-21 06:30:14 +03:00
parent 915bde6f96
commit af01b0ed48
3 changed files with 6 additions and 6 deletions

View File

@ -17,7 +17,7 @@ namespace osu.Game.Online
public class SignalRDerivedTypeWorkaroundJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType) =>
SignalRWorkaroundTypes.BASE_DERIVED.Any(t =>
SignalRWorkaroundTypes.BASE_TYPE_MAPPING.Any(t =>
objectType == t.baseType ||
objectType == t.derivedType);
@ -30,7 +30,7 @@ namespace osu.Game.Online
string type = (string)obj[@"$dtype"]!;
var resolvedType = SignalRWorkaroundTypes.BASE_DERIVED.Select(t => t.derivedType).Single(t => t.Name == type);
var resolvedType = SignalRWorkaroundTypes.BASE_TYPE_MAPPING.Select(t => t.derivedType).Single(t => t.Name == type);
object? instance = Activator.CreateInstance(resolvedType);

View File

@ -23,13 +23,13 @@ namespace osu.Game.Online
private static IReadOnlyDictionary<Type, IMessagePackFormatter> createFormatterMap()
{
IEnumerable<(Type derivedType, Type baseType)> baseDerived = SignalRWorkaroundTypes.BASE_DERIVED;
IEnumerable<(Type derivedType, Type baseType)> baseMap = SignalRWorkaroundTypes.BASE_TYPE_MAPPING;
// This should not be required. The fallback should work. But something is weird with the way caching is done.
// For future adventurers, I would not advise looking into this further. It's likely not worth the effort.
baseDerived = baseDerived.Concat(baseDerived.Select(t => (t.baseType, t.baseType))).Distinct();
baseMap = baseMap.Concat(baseMap.Select(t => (t.baseType, t.baseType)));
return new Dictionary<Type, IMessagePackFormatter>(baseDerived.Select(t =>
return new Dictionary<Type, IMessagePackFormatter>(baseMap.Select(t =>
{
var formatter = (IMessagePackFormatter)Activator.CreateInstance(typeof(TypeRedirectingFormatter<,>).MakeGenericType(t.derivedType, t.baseType));
return new KeyValuePair<Type, IMessagePackFormatter>(t.derivedType, formatter);

View File

@ -15,7 +15,7 @@ namespace osu.Game.Online
/// <seealso cref="SignalRDerivedTypeWorkaroundJsonConverter"/>
internal static class SignalRWorkaroundTypes
{
internal static readonly IReadOnlyList<(Type derivedType, Type baseType)> BASE_DERIVED = new[]
internal static readonly IReadOnlyList<(Type derivedType, Type baseType)> BASE_TYPE_MAPPING = new[]
{
(typeof(ChangeTeamRequest), typeof(MatchUserRequest)),
(typeof(TeamVersusRoomState), typeof(MatchRoomState)),