void AddPostOperation(IDebuggingHandler handler, OpenApiPathItem item, OpenApiOperation operation) { if (handler.GetType().ImplementsOpenGeneric(typeof(ICanHandlePostRequests <>))) { item.AddOperation(OperationType.Post, operation); } }
/// <inheritdoc/> public async Task InvokeDebugginHandlerMethod(HttpContext context, IDebuggingHandler handler, Type artifactType, object artifact) { if (HttpMethods.IsGet(context.Request.Method) && handler.GetType().ImplementsOpenGeneric(typeof(ICanHandleGetRequests <>))) { var method = _methodFinder.FindMethod(handler, typeof(ICanHandleGetRequests <>), artifactType); await InvokeHandlerMethod(context, method, handler, artifact).ConfigureAwait(false); return; } if (HttpMethods.IsPost(context.Request.Method) && handler.GetType().ImplementsOpenGeneric(typeof(ICanHandlePostRequests <>))) { var method = _methodFinder.FindMethod(handler, typeof(ICanHandlePostRequests <>), artifactType); await InvokeHandlerMethod(context, method, handler, artifact).ConfigureAwait(false); return; } }
/// <inheritdoc/> public MethodInfo FindMethod(IDebuggingHandler handler, Type handlerInterface, Type artifactType) { var handlerInterfaceTypeInfo = handlerInterface.GetTypeInfo(); var implementedGenericInterfaces = handler.GetType().GetInterfaces().Where(_ => _.IsGenericType); var matchingInterfaces = implementedGenericInterfaces.Where(_ => _.GetGenericTypeDefinition().GetTypeInfo() == handlerInterfaceTypeInfo); var suitableInterfaces = matchingInterfaces.Where(_ => _.GenericTypeArguments.Length == 1 && _.GenericTypeArguments[0].IsAssignableFrom(artifactType)); var interfaceMethods = suitableInterfaces.SelectMany(_ => _.GetMethods()); var handleMethods = interfaceMethods.Where(_ => _.Name.StartsWith("Handle", StringComparison.InvariantCultureIgnoreCase)); ThrowIfNoHandleMethodsWasFound(handleMethods, handler, handlerInterface, artifactType); ThrowIfMoreThanOneHandleMethodsWasFound(handleMethods, handler, handlerInterface, artifactType); return(handleMethods.First()); }
/// <summary> /// Initializes a new instance of the <see cref="NoAppropriateHandleMethodFound"/> class. /// </summary> /// <param name="handler">The <see cref="IDebuggingHandler"/> that was examined.</param> /// <param name="handlerInterface">The <see cref="Type"/> of the handler interface that was used.</param> /// <param name="artifactType">The <see cref="Type"/> of the artifact that should be handled.</param> public NoAppropriateHandleMethodFound(IDebuggingHandler handler, Type handlerInterface, Type artifactType) : base($"No appropriate Handle... method was found for {handler.GetType()} using the {handlerInterface} interface for artifacts of type {artifactType}.") { }