mirror of
https://github.com/AlexMacocian/Net.Sdk.Web.Extensions.git
synced 2026-07-15 13:39:29 +00:00
Support for synchronous lambdas
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
public class SimpleRoute2
|
||||
{
|
||||
[GeneratePost("somethingSimple")]
|
||||
public async Task<IResult> GetSomething()
|
||||
public IResult GetSomething()
|
||||
{
|
||||
return Results.Ok();
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.8.16</Version>
|
||||
<Version>0.8.17</Version>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>Alexandru Macocian</Authors>
|
||||
|
||||
@@ -255,12 +255,26 @@ public class UseRoutesGenerator : IIncrementalGenerator
|
||||
var variables = string.Join(", ", methodDeclarationSyntax.ParameterList.Parameters
|
||||
.Select(param => param.Identifier.Text));
|
||||
|
||||
return @$"
|
||||
/*
|
||||
* Generate an async lambda for Task<IResult> or a synchronous lambda for IResult returns. If neither are matched, do not generate any method
|
||||
*/
|
||||
var returnTypeSymbol = semanticModel.GetSymbolInfo(methodDeclarationSyntax.ReturnType).Symbol as ITypeSymbol;
|
||||
return returnTypeSymbol?.ToDisplayString() switch
|
||||
{
|
||||
"System.Threading.Tasks.Task<Microsoft.AspNetCore.Http.IResult>" => @$"
|
||||
builder.Map{type}(""{pattern}"", async (HttpContext httpContext, {classDeclarationSyntax.Identifier} route{(parameters.Length > 0 ? $", {parameters}" : "")}) =>
|
||||
{{
|
||||
var cancellationToken = httpContext.RequestAborted;
|
||||
return await route.{methodDeclarationSyntax.Identifier}({variables});
|
||||
}}){routeFilterSb};";
|
||||
}}){routeFilterSb};",
|
||||
"Microsoft.AspNetCore.Http.IResult" => @$"
|
||||
builder.Map{type}(""{pattern}"", (HttpContext httpContext, {classDeclarationSyntax.Identifier} route{(parameters.Length > 0 ? $", {parameters}" : "")}) =>
|
||||
{{
|
||||
var cancellationToken = httpContext.RequestAborted;
|
||||
return route.{methodDeclarationSyntax.Identifier}({variables});
|
||||
}}){routeFilterSb};",
|
||||
_ => default
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetMethodParameters(MethodDeclarationSyntax methodDeclaration)
|
||||
|
||||
Reference in New Issue
Block a user