提示词库

.NET提示词

用于 C# 和 ASP.NET Core 工作的提示词:审查异步代码、设计端点,以及迁移到当前的框架版本。

提示词是英文的,即它们的编写和测试所用的语言。这些页面上的说明和指引已翻译。

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

C# async 与 await 审查

审查 C# 代码中的阻塞调用、缺失的取消处理和未被观察的任务。

适用场景: 在发布前审查服务或控制器,担心线程池饥饿或死锁时。

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>

变量

{{code}}
要审查的 C# 文件或方法。

示例输入

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

示例输出

| 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);` |

仅为示意:为展示预期的形式而编写,并非由模型生成。

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

ASP.NET Core Minimal API 端点

编写带有验证、类型化结果和你指定状态码的 Minimal API 端点。

适用场景: 向 ASP.NET Core 服务添加端点,并希望统一处理验证和响应时。

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>

变量

{{specification}}
路由、方法、请求与响应字段、要调用的服务以及状态码。

示例输入

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

示例输出

```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

仅为示意:为展示预期的形式而编写,并非由模型生成。

改成你的

修改需求以符合你的标准,然后检查结果。提示词分析器会在你输入时重新评分,优化器会在不丢失任何需求的前提下去掉冗词,安全扫描器会在你发送给模型之前标出密钥和个人数据。

更多类别