public HandlerInstance( string method, IJsonRpcHandler handler, Type handlerInterface, Type? @params, Type?response, RequestProcessType?requestProcessType, Action disposeAction ) { _disposeAction = disposeAction; Handler = handler; ImplementationType = handler.GetType(); Method = method; 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 LspHandlerDescriptor( int index, string method, string key, IJsonRpcHandler handler, Type handlerType, Type? @params, Type?registrationType, string registrationMethod, object?registrationOptions, Type?capabilityType, RequestProcessType?requestProcessType, Action disposeAction, ILspHandlerTypeDescriptor?typeDescriptor, Guid?id ) { _disposeAction = disposeAction; Id = id.HasValue ? id.Value : handler is ICanBeIdentifiedHandler h && h.Id != Guid.Empty ? h.Id : Guid.NewGuid(); Method = method; Key = key; ImplementationType = handler.GetType(); Handler = handler; HandlerType = handlerType; Params = @params; RegistrationType = registrationType; RegistrationMethod = registrationMethod; RegistrationOptions = registrationOptions; CapabilityType = capabilityType; Response = @params?.GetInterfaces() .Where(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest <>)) .Select(x => x.GetGenericArguments()[0]) .OrderBy(x => x == typeof(Unit)) .FirstOrDefault() ?? typeDescriptor?.ResponseType ?? typeof(Unit); // If multiple are implemented this behavior is unknown CanBeResolvedHandlerType = handler.GetType().GetTypeInfo() ?.ImplementedInterfaces ?.FirstOrDefault(x => typeof(ICanBeResolvedHandler).IsAssignableFrom(x)); HasReturnType = Response != null && Response != typeof(Unit); IsDelegatingHandler = @params?.IsGenericType == true && ( typeof(DelegatingRequest <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) || typeof(DelegatingNotification <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) ); IsNotification = handlerType.GetInterfaces() .Any(z => z.IsGenericType && typeof(IJsonRpcNotificationHandler <>).IsAssignableFrom(z.GetGenericTypeDefinition())); IsRequest = !IsNotification; RequestProcessType = requestProcessType; TypeDescriptor = typeDescriptor; Index = index; IsBuiltIn = handler.GetType().GetCustomAttributes <BuiltInAttribute>().Any(); }
public LspHandlerDescriptor( string method, string key, IJsonRpcHandler handler, Type handlerType, Type @params, Type registrationType, object registrationOptions, Func <bool> allowsDynamicRegistration, Type capabilityType, RequestProcessType?requestProcessType, Action disposeAction, ILspHandlerTypeDescriptor typeDescriptor ) { _disposeAction = disposeAction; Id = Guid.NewGuid(); Method = method; Key = key; ImplementationType = handler.GetType(); Handler = handler; HandlerType = handlerType; Params = @params; RegistrationType = registrationType; RegistrationOptions = registrationOptions; _allowsDynamicRegistration = allowsDynamicRegistration; CapabilityType = capabilityType; Response = typeDescriptor?.ResponseType ?? @params?.GetInterfaces() .FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IRequest <>))? .GetGenericArguments()[0] ?? typeof(Unit); // If multiple are implemented this behavior is unknown CanBeResolvedHandlerType = handler.GetType().GetTypeInfo() .ImplementedInterfaces .FirstOrDefault(x => typeof(ICanBeResolvedHandler).IsAssignableFrom(x)); HasReturnType = Response != null && Response != typeof(Unit); IsDelegatingHandler = @params?.IsGenericType == true && ( typeof(DelegatingRequest <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) || typeof(DelegatingNotification <>).IsAssignableFrom(@params.GetGenericTypeDefinition()) ); IsNotification = typeof(IJsonRpcNotificationHandler).IsAssignableFrom(handlerType) || handlerType .GetInterfaces().Any( z => z.IsGenericType && typeof(IJsonRpcNotificationHandler <>).IsAssignableFrom( z.GetGenericTypeDefinition() ) ); IsRequest = !IsNotification; RequestProcessType = requestProcessType; TypeDescriptor = typeDescriptor; }
public LspHandlerDescriptor( string method, string key, IJsonRpcHandler handler, Type handlerType, Type? @params, Type?registrationType, object?registrationOptions, Func <bool> allowsDynamicRegistration, Type?capabilityType, RequestProcessType?requestProcessType, Action disposeAction, ILspHandlerTypeDescriptor?typeDescriptor ) : this( method, key, handler, handlerType, @params, registrationType, registrationOptions, allowsDynamicRegistration, capabilityType, requestProcessType, disposeAction, typeDescriptor, null ) { }
public LspHandlerDescriptor( int index, string method, string key, IJsonRpcHandler handler, Type handlerType, Type? @params, Type?registrationType, string registrationMethod, object?registrationOptions, Type?capabilityType, RequestProcessType?requestProcessType, Action disposeAction, ILspHandlerTypeDescriptor?typeDescriptor ) : this( index, method, key, handler, handlerType, @params, registrationType, registrationMethod, registrationOptions, capabilityType, requestProcessType, disposeAction, typeDescriptor, null ) { }