Apply nullable

This commit is contained in:
Dean Herbert
2021-12-03 15:49:01 +09:00
parent 79d723172a
commit f9ad307526

View File

@ -15,6 +15,8 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko; using osu.Game.Rulesets.Taiko;
#nullable enable
namespace osu.Desktop.LegacyIpc namespace osu.Desktop.LegacyIpc
{ {
/// <summary> /// <summary>
@ -27,7 +29,7 @@ namespace osu.Desktop.LegacyIpc
/// <summary> /// <summary>
/// Invoked when a message is received from a legacy client. /// Invoked when a message is received from a legacy client.
/// </summary> /// </summary>
public new Func<object, object> MessageReceived; public new Func<object, object>? MessageReceived;
public LegacyTcpIpcProvider() public LegacyTcpIpcProvider()
: base(45357) : base(45357)
@ -42,8 +44,10 @@ namespace osu.Desktop.LegacyIpc
var legacyData = ((JObject)msg.Value).ToObject<LegacyIpcMessage.Data>(); var legacyData = ((JObject)msg.Value).ToObject<LegacyIpcMessage.Data>();
object value = parseObject((JObject)legacyData!.MessageData, legacyData.MessageType); object value = parseObject((JObject)legacyData!.MessageData, legacyData.MessageType);
object result = onLegacyIpcMessageReceived(value); return new LegacyIpcMessage
return result != null ? new LegacyIpcMessage { Value = result } : null; {
Value = onLegacyIpcMessageReceived(value)
};
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -58,10 +62,12 @@ namespace osu.Desktop.LegacyIpc
switch (type) switch (type)
{ {
case nameof(LegacyIpcDifficultyCalculationRequest): case nameof(LegacyIpcDifficultyCalculationRequest):
return value.ToObject<LegacyIpcDifficultyCalculationRequest>(); return value.ToObject<LegacyIpcDifficultyCalculationRequest>()
?? throw new InvalidOperationException($"Failed to parse request {value}");
case nameof(LegacyIpcDifficultyCalculationResponse): case nameof(LegacyIpcDifficultyCalculationResponse):
return value.ToObject<LegacyIpcDifficultyCalculationResponse>(); return value.ToObject<LegacyIpcDifficultyCalculationResponse>()
?? throw new InvalidOperationException($"Failed to parse request {value}");
default: default:
throw new ArgumentException($"Unsupported object type {type}"); throw new ArgumentException($"Unsupported object type {type}");