Skip to content

LuffyDis/GitHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Dynamic C# Class Generation via Prompts

System for generating structured LLM prompts that produce C# API controller classes.

Structure

src/
  Controllers/          # Example output: what the generated class looks like
    ProductsController.cs
  Prompts/
    ControllerPromptBuilder.cs   # Core: builds the prompt from parameters
examples/
  Example_GeneratePrompts.cs     # Usage examples with different configs

How it works

  1. Define a ControllerPromptParameters object with your desired configuration
  2. Call ControllerPromptBuilder.Build(parameters) to produce a prompt string
  3. Send that prompt to an LLM — it returns a complete C# controller class

Parameters

Parameter Type Description
EntityName string Name of the entity (e.g. Product)
Namespace string C# namespace for the controller
RoutePrefix string Route template (default: api/[controller])
UseAuthorization bool Add [Authorize] attribute
AuthorizationPolicy string? Named authorization policy
UseApiVersioning bool Add [ApiVersion] attribute
ApiVersion string? Version string (e.g. "2.0")
UseMediatR bool Use MediatR instead of service injection
UseFluentValidation bool Note FluentValidation in prompt
GenerateSwaggerAnnotations bool Add [ProducesResponseType]
Actions List HTTP actions to generate

Quick example

var parameters = new ControllerPromptParameters
{
    EntityName = "Product",
    Actions = new()
    {
        new ActionDefinition
        {
            HttpMethod = "Get",
            ActionName = "GetAll",
            ReturnDtoType = "ProductDto",
            IsCollection = true
        }
    }
};

string prompt = ControllerPromptBuilder.Build(parameters);
// Send `prompt` to your LLM of choice

Generated prompt (excerpt)

You are an expert C# .NET developer.
Generate ONLY the C# source code for the class described below.

## Class to generate

- **Type**: ASP.NET Core API Controller
- **Class name**: `ProductsController`
- **Namespace**: `MyApi.Controllers`
- **Route**: `[Route("api/[controller]")]`
- **Attributes**: `[ApiController]`

## Actions

### GetAll

- **HTTP Method**: `[HttpGet]`
- **Return type**: `async Task<IActionResult>`
- **ProducesResponseType**: `typeof(IEnumerable<ProductDto>)` with status `200`

About

Script from git

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages