DamianEdwards / RazorSlices

Lightweight Razor-based templates for ASP.NET Core without MVC, Razor Pages, or Blazor.
MIT License
297 stars 12 forks source link

Source Generator #41

Closed madeyoga closed 1 month ago

madeyoga commented 2 months ago

I have implemented a source generator to create IRazorSliceProxy implementations. I have also added the generator project reference to RazorSlices.Samples.WebApp.csproj and RazorSlices.Samples.RazorClassLibrary.csproj.

However, I'm encountering an error specifically with the /lorem-stream endpoint in the samples project.

Error code CS9144
Cannot intercept method 'EndpointRouteBuilderExtensions.MapGet(IEndpointRouteBuilder, string, RequestDelegate)' 
with interceptor 
'GeneratedRouteBuilderExtensionsCore.MapGet4(IEndpointRouteBuilder, string, Delegate)' 
because the signatures do not match.    
RazorSlices.Samples.WebApp (net7.0) 
G:\RazorSlices\samples\RazorSlices.Samples.WebApp\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensions.g.cs
madeyoga commented 2 months ago

I have added type name validation to the generator. The validation ensures the type name adheres to the following rules:

If the filename contain an invalid type name, the current code will attempt to fix it.

I'm unsure whether I should fix the type name in this case.

DamianEdwards commented 1 month ago

This is great, thank you! I'm going to merge this into the aot branch so we can continue to refine it. Thanks again!