Given the code:
public static void TestGenericParam<TUser>(IEndpointRouteBuilder app) where TUser : class { app.MapPost("/test-param", ([FromServices] UserManager<TUser> userManager) => { }); } public static void TestGenericResponse<TUser>(IEndpointRouteBuilder app) where TUser : new() { app.MapPost("/test-return", () => new TUser()); }
RDG will generate code that fails to compile because TUser
is undefined. As a short-term mitigation, we can skip generating MapPost
and similar methods when we see an open generic parameter in the delegate signature. Long term, we can look at flowing the generic parameters through the Map
methods we generate which can then hopefully be inferred.
GeneratedRouteBuilderExtensions.g.cs(73,85): error CS0246: The type or namespace name 'TUser' could not be found (are you missing a using directive or an assembly reference?)
GeneratedRouteBuilderExtensions.g.cs(88,33): error CS0246: The type or namespace name 'TUser' could not be found (are you missing a using directive or an assembly reference?)
internal static global::Microsoft.AspNetCore.Builder.RouteHandlerBuilder MapPost( this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, [global::System.Diagnostics.CodeAnalysis.StringSyntax("Route")] string pattern, global::System.Action<global::Microsoft.AspNetCore.Identity.UserManager<TUser>> handler, // <---- Error! [global::System.Runtime.CompilerServices.CallerFilePath] string filePath = "", [global::System.Runtime.CompilerServices.CallerLineNumber]int lineNumber = 0) { // ... handler(ic.GetArgument<global::Microsoft.AspNetCore.Identity.UserManager<TUser>>(0)!); // ... var userManager_local = httpContext.RequestServices.GetRequiredService<Microsoft.AspNetCore.Identity.UserManager<TUser>>(); // ... var handler = (Func<TUser>)del; // ... var jsonTypeInfo = (JsonTypeInfo<TUser>)serializerOptions.GetTypeInfo(typeof(TUser));
PaulusParssinen and Jure-BB
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4