Skip to content

Commit d744159

Browse files
Moved if directive to common extension class to avoid scattering directives in implementations.
1 parent 4a70156 commit d744159

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/ModelContextProtocol/Shared/McpSession.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,7 @@ public async Task<JsonRpcResponse> SendRequestAsync(JsonRpcRequest request, Canc
397397
finally
398398
{
399399
_pendingRequests.TryRemove(request.Id, out _);
400-
#if NETSTANDARD2_0
401-
registration.Dispose();
402-
#else
403400
await registration.DisposeAsync().ConfigureAwait(false);
404-
#endif
405401
FinalizeDiagnostics(activity, startingTimestamp, durationMetric, ref tags);
406402
}
407403
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#if NETSTANDARD2_0
2+
3+
using System.Diagnostics;
4+
5+
/// <summary>
6+
/// Only used for .NET Standard 2.0.
7+
/// This class is a workaround for the lack of DisposeAsync.
8+
/// This allows us to reduce the number of #if directives in the code.
9+
/// </summary>
10+
internal static class TargetFrameworkExtensions
11+
{
12+
public static Task DisposeAsync(this CancellationTokenRegistration registration)
13+
{
14+
registration.Dispose();
15+
return Task.CompletedTask;
16+
}
17+
}
18+
19+
#endif

0 commit comments

Comments
 (0)