Prompt-Bibliothek

.NET-Prompts

Prompts für C# und ASP.NET Core: asynchronen Code prüfen, Endpunkte entwerfen und auf aktuelle Framework-Versionen migrieren.

Die Prompts sind auf Englisch, der Sprache, in der sie geschrieben und getestet wurden. Beschreibungen und Hinweise auf diesen Seiten sind übersetzt.

  • csharp
  • async
  • code review
100/100 · 161 Tokens

Review von async und await in C#

Prüft C#-Code auf blockierende Aufrufe, fehlenden Abbruch und unbeobachtete Tasks.

Einsetzen, wenn: Beim Review eines Dienstes oder Controllers vor dem Release, wenn Thread-Pool-Erschöpfung oder Deadlocks ein Thema sind.

prompt
You are a senior .NET engineer reviewing asynchronous C# code.

## Task
Review the C# code below for incorrect use of async and await.

## Requirements
- Flag every call to .Result, .Wait(), or .GetAwaiter().GetResult() on a task.
- Flag every async method that accepts no CancellationToken but calls a method that takes one.
- Flag every async void method that is not an event handler.
- Report only issues you can point to in the code.
- Give the corrected line for every issue.

## Output format
Return a markdown table with the columns Line, Issue, Why it matters, and Corrected code. If there are no issues, return the single line "No async issues found."

## Input
<code>
{{code}}
</code>

Variablen

{{code}}
Die C#-Datei oder die zu prüfenden Methoden.

Beispieleingabe

code: an OrdersController with a Get action that calls _repo.GetAsync(id).Result.

Beispielausgabe

| Line | Issue | Why it matters | Corrected code |
|---|---|---|---|
| 18 | `.Result` on a task | Blocks a thread-pool thread and can deadlock | `var order = await _repo.GetAsync(id, ct);` |

Beispielhaft: geschrieben, um die erwartete Form zu zeigen, nicht von einem Modell erzeugt.

  • aspnet core
  • api
  • csharp
100/100 · 146 Tokens

ASP.NET-Core-Minimal-API-Endpunkt

Schreibt einen Minimal-API-Endpunkt mit Validierung, typisierten Ergebnissen und den von Ihnen angegebenen Statuscodes.

Einsetzen, wenn: Beim Hinzufügen eines Endpunkts zu einem ASP.NET-Core-Dienst, wenn Validierung und Antworten einheitlich behandelt werden sollen.

prompt
You are a senior .NET engineer writing ASP.NET Core minimal APIs.

## Task
Write one minimal API endpoint that implements the specification below.

## Requirements
- Use TypedResults for every response.
- Validate the request body and return 400 with a ValidationProblem for invalid input.
- Accept a CancellationToken and pass it to every awaited call.
- Use only the types and services named in the specification.
- Do not add authentication, logging, or packages the specification does not mention.

## Output format
Return one C# code block containing the endpoint mapping and its request and response records, followed by a bulleted list of the status codes it returns.

## Input
<specification>
{{specification}}
</specification>

Variablen

{{specification}}
Route, Methode, Anfrage- und Antwortfelder, der aufzurufende Dienst und die Statuscodes.

Beispieleingabe

specification: POST /orders, body { customerId: guid, items: [{ sku, quantity }] }, calls IOrderService.CreateAsync, returns 201 with the order id, 400 on invalid input.

Beispielausgabe

```csharp
app.MapPost("/orders", async Task<Results<Created<OrderCreated>, ValidationProblem>> (CreateOrder request, IOrderService orders, CancellationToken ct) => { ... });
```
- 201 Created with the order id
- 400 with validation errors

Beispielhaft: geschrieben, um die erwartete Form zu zeigen, nicht von einem Modell erzeugt.

Machen Sie ihn zu Ihrem

Passen Sie die Anforderungen an Ihre Standards an und prüfen Sie dann das Ergebnis. Der Prompt-Analyzer bewertet neu, während Sie tippen, der Optimierer entfernt Füllwörter, ohne eine Anforderung zu verlieren, und der Sicherheitsscanner markiert Geheimnisse und personenbezogene Daten, bevor Sie den Prompt an ein Modell senden.

Weitere Kategorien