© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
46 replies
ero

Creating and using an incremental source generator

I wanna create an incremental source generator for my web API project, but I cannot for the life of me understand how to create a source generator at all. I'm even having a hard time understanding the documentation that does exist. Is there anyone that's able to help?

I have a pretty clear idea of what I wanna do: I have a collection of HTTP endpoints in one class, which get turned into controllers, commands, and DTOs.

namespace Endpoints;

[GenerateHttpEndpoints] // better name ideas?
public partial class User
{
  [HttpPost("/api/users")]
  public async Task<ActionResult<Entities.User>> Create(
    string name,
    string email,
    string password)
  {
    // ...

    return Ok(createdUser);
  }
}
namespace Endpoints;

[GenerateHttpEndpoints] // better name ideas?
public partial class User
{
  [HttpPost("/api/users")]
  public async Task<ActionResult<Entities.User>> Create(
    string name,
    string email,
    string password)
  {
    // ...

    return Ok(createdUser);
  }
}

UserEndpoints.g.cs
UserEndpoints.g.cs

file record CreateUserDto(
  string Name,
  string Email,
  string Password);

// other things related to handling the command
file record CreateUserDto(
  string Name,
  string Email,
  string Password);

// other things related to handling the command
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Incremental Generator
C#CC# / help
3y ago
❔ Incremental source generator not called with docker
C#CC# / help
3y ago
❔ Incremental Generator compilation error
C#CC# / help
3y ago
❔ Source generator for creating REST Api
C#CC# / help
3y ago