Skip to content

Commit

Permalink
Allow nullable for Services
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Aug 13, 2023
1 parent 356797d commit cee6363
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
12 changes: 9 additions & 3 deletions Lagrange.Core.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.Core", "Lagrange.Core\Lagrange.Core.csproj", "{909C99CC-0CB7-4A34-8C75-AD25E6AEA535}"
# Visual Studio Version 17
VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lagrange.Core", "Lagrange.Core\Lagrange.Core.csproj", "{909C99CC-0CB7-4A34-8C75-AD25E6AEA535}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.Core.Test", "Lagrange.Core.Test\Lagrange.Core.Test.csproj", "{D64B6BAB-CD20-4660-8A6E-BCC936652204}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lagrange.Core.Test", "Lagrange.Core.Test\Lagrange.Core.Test.csproj", "{D64B6BAB-CD20-4660-8A6E-BCC936652204}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.OneBot", "Lagrange.OneBot\Lagrange.OneBot.csproj", "{37AEDD3B-9B9F-4782-ADD5-BA2436FB2507}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lagrange.OneBot", "Lagrange.OneBot\Lagrange.OneBot.csproj", "{37AEDD3B-9B9F-4782-ADD5-BA2436FB2507}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -25,4 +28,7 @@ Global
{37AEDD3B-9B9F-4782-ADD5-BA2436FB2507}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37AEDD3B-9B9F-4782-ADD5-BA2436FB2507}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
3 changes: 1 addition & 2 deletions Lagrange.Core/Core/Context/ServiceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Lagrange.Core.Core.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract

namespace Lagrange.Core.Core.Context;

Expand Down Expand Up @@ -104,7 +103,7 @@ public List<ProtocolEvent> ResolveEventByPacket(SsoPacket packet)

if (success)
{
result.Add(@event);
if (@event != null) result.Add(@event);
if (extraEvents != null) result.AddRange(extraEvents);

Collection.Log.LogVerbose(Tag, $"Incoming SSOFrame: {packet.Command}");
Expand Down
6 changes: 3 additions & 3 deletions Lagrange.Core/Core/Service/Abstraction/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ protected virtual bool Build(TEvent input, BotKeystore keystore, BotAppInfo appI
return (output = null!) != null;
}

bool IService.Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out ProtocolEvent output, out List<ProtocolEvent>? extraEvents)
bool IService.Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out ProtocolEvent? output, out List<ProtocolEvent>? extraEvents)
{
bool result = Parse(input, keystore, appInfo, device, out var @event, out extraEvents);
output = @event;
return result;
}

bool IService.Build(ProtocolEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out BinaryPacket output, out List<BinaryPacket>? extraPackets) =>
out BinaryPacket? output, out List<BinaryPacket>? extraPackets) =>
Build((TEvent) input, keystore, appInfo, device, out output, out extraPackets);
}
4 changes: 2 additions & 2 deletions Lagrange.Core/Core/Service/Abstraction/IService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Lagrange.Core.Core.Service.Abstraction;
internal interface IService
{
public bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out ProtocolEvent output, out List<ProtocolEvent>? extraEvents);
out ProtocolEvent? output, out List<ProtocolEvent>? extraEvents);

public bool Build(ProtocolEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out BinaryPacket output, out List<BinaryPacket>? extraPackets);
out BinaryPacket? output, out List<BinaryPacket>? extraPackets);
}

0 comments on commit cee6363

Please sign in to comment.