admin管理员组文章数量:1122832
I want to ensure that my IDE, during autocomplete for function parameters, suggests only (or at least prioritizes) the parameters that are allowed in the function. Specifically, this pertains to an extension function for the MediatR library. The following example illustrates the problem:
using MediatR;
namespace ITaskTest;
public class Result<T> {
public T Value { get; set; }
public string ErrorMessage { get; set; }
}
public class Result { }
public interface ITask : IRequest<Result>;
public interface ITask<TResponse> : IRequest<Result<TResponse>>;
public record TestTask : ITask;
public record TestTaskGeneric : ITask<TestTaskGenericResponse>;
public record TestTaskGenericResponse(string Message);
public static class MediatorExtensions
{
public static async Task<Result> RunTask(this IMediator mediator, ITask task) {
return await mediator.Send(task);
}
public static async Task<Result<TResponse>> RunTaskGeneric<TResponse>(this IMediator mediator, ITask<TResponse> task) {
return await mediator.Send(task);
}
}
public class Class1
{
private readonly IMediator mediator;
public Class1(IMediator mediator) {
this.mediator = mediator;
}
public async Task Test() {
// IDE should suggest TestTask here -> does work!
var result = await mediator.RunTask(new TestTask());
// IDE should suggest TestTaskGeneric here -> does not work!
var resultGeneric = await mediator.RunTaskGeneric(new TestTaskGeneric());
}
}
Also see images for example.
does work
does not work
The reason why this makes sense: I have a large number of ITask
implementations as well as some other interfaces like IQuery
and ICommand
. During development, I want to limit the selection of options. Additionally, it doesn't make sense for options like TestTaskGenericResponse
to be suggested as a possible parameter. The IDE even immediately points out that it’s not a valid parameter but still suggests it.
Am I missing something here? Or is something like this generally not possible?
I’ve tried various configurations and asked ChatGPT multiple times, but I haven’t been able to find a solution.
本文标签:
版权声明:本文标题:.net - Getting my IDE to show autocompletion for only generic typ specified in interface (using MediatR, C#) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736307641a1933383.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论