-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathHandlerDescriptor.cs
62 lines (56 loc) · 2.43 KB
/
HandlerDescriptor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Diagnostics;
using System.Linq;
using MediatR;
using OmniSharp.Extensions.JsonRpc;
namespace OmniSharp.Extensions.DebugAdapter.Shared
{
[DebuggerDisplay("{Method}")]
internal class HandlerDescriptor : IHandlerDescriptor, IDisposable
{
private readonly Action _disposeAction;
public HandlerDescriptor(
string method, IHandlerTypeDescriptor typeDescriptor, IJsonRpcHandler handler, Type handlerInterface, Type @params, Type response,
RequestProcessType? requestProcessType, Action disposeAction
)
{
_disposeAction = disposeAction;
Handler = handler;
ImplementationType = handler.GetType();
Method = method;
TypeDescriptor = typeDescriptor;
HandlerType = handlerInterface;
Params = @params;
Response = response;
HasReturnType = HandlerType.GetInterfaces().Any(
@interface =>
@interface.IsGenericType &&
typeof(IRequestHandler<,>).IsAssignableFrom(@interface.GetGenericTypeDefinition())
);
IsDelegatingHandler = @params?.IsGenericType == true &&
(
typeof(DelegatingRequest<>).IsAssignableFrom(@params.GetGenericTypeDefinition()) ||
typeof(DelegatingNotification<>).IsAssignableFrom(@params.GetGenericTypeDefinition())
);
IsNotification = handlerInterface.GetInterfaces().Any(
z => z.IsGenericType &&
typeof(IJsonRpcNotificationHandler<>).IsAssignableFrom(z.GetGenericTypeDefinition())
);
IsRequest = !IsNotification;
RequestProcessType = requestProcessType;
}
public IJsonRpcHandler Handler { get; }
public bool IsNotification { get; }
public bool IsRequest { get; }
public Type HandlerType { get; }
public Type ImplementationType { get; }
public string Method { get; }
public IHandlerTypeDescriptor TypeDescriptor { get; }
public Type Params { get; }
public Type Response { get; }
public bool HasReturnType { get; }
public bool IsDelegatingHandler { get; }
public RequestProcessType? RequestProcessType { get; }
public void Dispose() => _disposeAction();
}
}