Create `@static` directive that results in a static class being generated
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
I would like to create small static extension methods that allow me to utilize razor markup syntax. This was best summarized by Damian in a different thread, so I will quote him here.
> Is it fair to summarize this as supporting a new kind of .razor file template that produces a static class rather than a component type, and within it only a `@code` block containing static methods (using Razor syntax or otherwise) would be allowed? Perhaps by a new `@static` directive that is mutually exclusive with other directives that assume a non-static type (e.g. `@inherits`, `@inject`, etc.):
> ```razor
> @static
> @code {
> extension(ComponentFactoryCollection componentFactories)
> {
> public void AddMyOtherComponentStub()
> {
> @
> @parameters.Get(x => x.ChildContent)
>
> }
> }
> }
> ```
My personal preference would be to omit the `@code { }` ceremony and just assume your creating static methods, but I'll let you guys figure out those details.
Original feature request and my motivation are in the ASP.NET Core Roadmap discussion.
https://github.com/dotnet/aspnetcore/discussions/64788#discussioncomment-15594089
Contributor guide
Research direction
Start with the linked ASP.NET Core Roadmap discussion, then inspect how Roslyn handles Razor-related language or code-generation requests. Determine the accepted semantics for a new @static directive, including its allowed contents and interaction with other directives; completion requires an agreed design and implementation plan.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100