mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 15:44:04 +09:00
BASE_DERIVED
-> BASE_TYPE_MAPPING
This commit is contained in:
@ -17,7 +17,7 @@ namespace osu.Game.Online
|
|||||||
public class SignalRDerivedTypeWorkaroundJsonConverter : JsonConverter
|
public class SignalRDerivedTypeWorkaroundJsonConverter : JsonConverter
|
||||||
{
|
{
|
||||||
public override bool CanConvert(Type objectType) =>
|
public override bool CanConvert(Type objectType) =>
|
||||||
SignalRWorkaroundTypes.BASE_DERIVED.Any(t =>
|
SignalRWorkaroundTypes.BASE_TYPE_MAPPING.Any(t =>
|
||||||
objectType == t.baseType ||
|
objectType == t.baseType ||
|
||||||
objectType == t.derivedType);
|
objectType == t.derivedType);
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ namespace osu.Game.Online
|
|||||||
|
|
||||||
string type = (string)obj[@"$dtype"]!;
|
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);
|
object? instance = Activator.CreateInstance(resolvedType);
|
||||||
|
|
||||||
|
@ -23,13 +23,13 @@ namespace osu.Game.Online
|
|||||||
|
|
||||||
private static IReadOnlyDictionary<Type, IMessagePackFormatter> createFormatterMap()
|
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.
|
// 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.
|
// 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));
|
var formatter = (IMessagePackFormatter)Activator.CreateInstance(typeof(TypeRedirectingFormatter<,>).MakeGenericType(t.derivedType, t.baseType));
|
||||||
return new KeyValuePair<Type, IMessagePackFormatter>(t.derivedType, formatter);
|
return new KeyValuePair<Type, IMessagePackFormatter>(t.derivedType, formatter);
|
||||||
|
@ -15,7 +15,7 @@ namespace osu.Game.Online
|
|||||||
/// <seealso cref="SignalRDerivedTypeWorkaroundJsonConverter"/>
|
/// <seealso cref="SignalRDerivedTypeWorkaroundJsonConverter"/>
|
||||||
internal static class SignalRWorkaroundTypes
|
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(ChangeTeamRequest), typeof(MatchUserRequest)),
|
||||||
(typeof(TeamVersusRoomState), typeof(MatchRoomState)),
|
(typeof(TeamVersusRoomState), typeof(MatchRoomState)),
|
||||||
|
Reference in New Issue
Block a user