fix: allow null in CallGateChannel args

This commit is contained in:
goat 2022-02-14 04:56:27 +01:00
parent e62984d270
commit 7864570a56
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
2 changed files with 30 additions and 1 deletions

View file

@ -0,0 +1,21 @@
using System;
namespace Dalamud.Plugin.Ipc.Exceptions;
/// <summary>
/// This exception is thrown when a null value is passed to an IPC requiring a value type.
/// </summary>
public class IpcValueNullError : IpcError
{
/// <summary>
/// Initializes a new instance of the <see cref="IpcValueNullError"/> class.
/// </summary>
/// <param name="name">Name of the IPC.</param>
/// <param name="expectedType">The type expected.</param>
/// <param name="index">Index of the failing argument.</param>
public IpcValueNullError(string name, Type expectedType, int index)
: base($"IPC {name} expects a value type({expectedType.FullName}) at index {index}, null given.")
{
// ignored
}
}

View file

@ -105,7 +105,7 @@ namespace Dalamud.Plugin.Ipc.Internal
var paramTypes = methodInfo.GetParameters()
.Select(pi => pi.ParameterType).ToArray();
if (args.Length != paramTypes.Length)
if (args?.Length != paramTypes.Length)
throw new IpcLengthMismatchError(this.Name, args.Length, paramTypes.Length);
for (var i = 0; i < args.Length; i++)
@ -113,6 +113,14 @@ namespace Dalamud.Plugin.Ipc.Internal
var arg = args[i];
var paramType = paramTypes[i];
if (arg == null)
{
if (paramType.IsValueType)
throw new IpcValueNullError(this.Name, paramType, i);
continue;
}
var argType = arg.GetType();
if (argType != paramType)
{