diff --git a/src/StreamJsonRpc/Reflection/TargetMethod.cs b/src/StreamJsonRpc/Reflection/TargetMethod.cs
index bc8f74dc3..fecc56d4c 100644
--- a/src/StreamJsonRpc/Reflection/TargetMethod.cs
+++ b/src/StreamJsonRpc/Reflection/TargetMethod.cs
@@ -70,6 +70,20 @@ internal TargetMethod(
}
}
+ ///
+ /// Gets the runtime type of the target object, if there is one.
+ ///
+ ///
+ /// Even when a matching target method is found, there may not be a target object
+ /// if the target method is .
+ ///
+ public Type? TargetObjectType => this.target?.GetType();
+
+ ///
+ /// Gets the that will be invoked to handle the request, if one was found.
+ ///
+ public MethodInfo? TargetMethodInfo => this.signature?.MethodInfo;
+
///
/// Gets all the exceptions thrown while trying to deserialize arguments to candidate parameter types.
///
diff --git a/src/StreamJsonRpc/net6.0/PublicAPI.Unshipped.txt b/src/StreamJsonRpc/net6.0/PublicAPI.Unshipped.txt
index 3e65b072f..fe4365bb5 100644
--- a/src/StreamJsonRpc/net6.0/PublicAPI.Unshipped.txt
+++ b/src/StreamJsonRpc/net6.0/PublicAPI.Unshipped.txt
@@ -4,3 +4,5 @@ StreamJsonRpc.JsonRpc.JoinableTaskTracker.get -> StreamJsonRpc.JsonRpc.JoinableT
StreamJsonRpc.JsonRpc.JoinableTaskTracker.set -> void
StreamJsonRpc.RpcMarshalableAttribute.CallScopedLifetime.get -> bool
StreamJsonRpc.RpcMarshalableAttribute.CallScopedLifetime.init -> void
+StreamJsonRpc.TargetMethod.TargetMethodInfo.get -> System.Reflection.MethodInfo?
+StreamJsonRpc.TargetMethod.TargetObjectType.get -> System.Type?
diff --git a/src/StreamJsonRpc/net8.0/PublicAPI.Unshipped.txt b/src/StreamJsonRpc/net8.0/PublicAPI.Unshipped.txt
index 3e65b072f..fe4365bb5 100644
--- a/src/StreamJsonRpc/net8.0/PublicAPI.Unshipped.txt
+++ b/src/StreamJsonRpc/net8.0/PublicAPI.Unshipped.txt
@@ -4,3 +4,5 @@ StreamJsonRpc.JsonRpc.JoinableTaskTracker.get -> StreamJsonRpc.JsonRpc.JoinableT
StreamJsonRpc.JsonRpc.JoinableTaskTracker.set -> void
StreamJsonRpc.RpcMarshalableAttribute.CallScopedLifetime.get -> bool
StreamJsonRpc.RpcMarshalableAttribute.CallScopedLifetime.init -> void
+StreamJsonRpc.TargetMethod.TargetMethodInfo.get -> System.Reflection.MethodInfo?
+StreamJsonRpc.TargetMethod.TargetObjectType.get -> System.Type?
diff --git a/src/StreamJsonRpc/netstandard2.0/PublicAPI.Unshipped.txt b/src/StreamJsonRpc/netstandard2.0/PublicAPI.Unshipped.txt
index 3e65b072f..fe4365bb5 100644
--- a/src/StreamJsonRpc/netstandard2.0/PublicAPI.Unshipped.txt
+++ b/src/StreamJsonRpc/netstandard2.0/PublicAPI.Unshipped.txt
@@ -4,3 +4,5 @@ StreamJsonRpc.JsonRpc.JoinableTaskTracker.get -> StreamJsonRpc.JsonRpc.JoinableT
StreamJsonRpc.JsonRpc.JoinableTaskTracker.set -> void
StreamJsonRpc.RpcMarshalableAttribute.CallScopedLifetime.get -> bool
StreamJsonRpc.RpcMarshalableAttribute.CallScopedLifetime.init -> void
+StreamJsonRpc.TargetMethod.TargetMethodInfo.get -> System.Reflection.MethodInfo?
+StreamJsonRpc.TargetMethod.TargetObjectType.get -> System.Type?
diff --git a/src/StreamJsonRpc/netstandard2.1/PublicAPI.Unshipped.txt b/src/StreamJsonRpc/netstandard2.1/PublicAPI.Unshipped.txt
index 3e65b072f..fe4365bb5 100644
--- a/src/StreamJsonRpc/netstandard2.1/PublicAPI.Unshipped.txt
+++ b/src/StreamJsonRpc/netstandard2.1/PublicAPI.Unshipped.txt
@@ -4,3 +4,5 @@ StreamJsonRpc.JsonRpc.JoinableTaskTracker.get -> StreamJsonRpc.JsonRpc.JoinableT
StreamJsonRpc.JsonRpc.JoinableTaskTracker.set -> void
StreamJsonRpc.RpcMarshalableAttribute.CallScopedLifetime.get -> bool
StreamJsonRpc.RpcMarshalableAttribute.CallScopedLifetime.init -> void
+StreamJsonRpc.TargetMethod.TargetMethodInfo.get -> System.Reflection.MethodInfo?
+StreamJsonRpc.TargetMethod.TargetObjectType.get -> System.Type?
diff --git a/test/StreamJsonRpc.Tests/JsonRpcDelegatedDispatchAndSendTests.cs b/test/StreamJsonRpc.Tests/JsonRpcDelegatedDispatchAndSendTests.cs
index e512924e7..53e7d3cb3 100644
--- a/test/StreamJsonRpc.Tests/JsonRpcDelegatedDispatchAndSendTests.cs
+++ b/test/StreamJsonRpc.Tests/JsonRpcDelegatedDispatchAndSendTests.cs
@@ -1,9 +1,5 @@
using System.Diagnostics;
using Microsoft.VisualStudio.Threading;
-using StreamJsonRpc;
-using StreamJsonRpc.Protocol;
-using Xunit;
-using Xunit.Abstractions;
public class JsonRpcDelegatedDispatchAndSendTests : TestBase
{
@@ -37,6 +33,14 @@ public async Task DispatchRequestIsPassedCorrectTypeOfRequest()
Assert.Equal("StreamJsonRpc.JsonMessageFormatter+InboundJsonRpcRequest", this.serverRpc.LastRequestDispatched?.GetType().FullName);
}
+ [Fact]
+ public async Task DispatchRequestTargetMethod()
+ {
+ await this.clientRpc.InvokeAsync(nameof(Server.TestMethodAsync));
+ Assert.Equal(typeof(Server), this.serverRpc.LastTargetMethodDispatched?.TargetObjectType);
+ Assert.Equal(typeof(Server).GetMethod(nameof(Server.TestMethodAsync)), this.serverRpc.LastTargetMethodDispatched?.TargetMethodInfo);
+ }
+
[Fact]
public async Task DelegatedDispatcherCanDispatchInReverseOrderBasedOnTopLevelProperty()
{
@@ -84,7 +88,7 @@ public class DelegatedJsonRpc : JsonRpc
{
private const string MessageOrderPropertyName = "messageOrder";
- private AsyncQueue<(JsonRpcRequest, TaskCompletionSource, Task)> requestSignalQueue = new AsyncQueue<(JsonRpcRequest, TaskCompletionSource, Task)>();
+ private readonly AsyncQueue<(JsonRpcRequest, TaskCompletionSource, Task)> requestSignalQueue = new AsyncQueue<(JsonRpcRequest, TaskCompletionSource, Task)>();
private int messageCounter = 0;
public DelegatedJsonRpc(IJsonRpcMessageHandler handler)
@@ -101,6 +105,8 @@ public DelegatedJsonRpc(IJsonRpcMessageHandler handler, object target)
public JsonRpcRequest? LastRequestDispatched { get; private set; }
+ public TargetMethod? LastTargetMethodDispatched { get; private set; }
+
public async Task FlushRequestQueueAsync(int expectedCount)
{
var requests = new SortedList, Task)>();
@@ -124,6 +130,7 @@ public async Task FlushRequestQueueAsync(int expectedCount)
protected override async ValueTask DispatchRequestAsync(JsonRpcRequest request, TargetMethod targetMethod, CancellationToken cancellationToken)
{
this.LastRequestDispatched = request;
+ this.LastTargetMethodDispatched = targetMethod;
TaskCompletionSource? completionTcs = null;
if (this.EnableBuffering)