プロンプトライブラリ

.NETのプロンプト

C# と ASP.NET Core 向けのプロンプト:非同期コードのレビュー、エンドポイント設計、最新のフレームワークバージョンへの移行。

プロンプト本体は、作成・テストした言語である英語です。これらのページの説明と案内文は翻訳されています。

  • csharp
  • async
  • code review
100/100 · 161 トークン

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 トークン

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

例示です。期待される形を示すために書いたもので、モデルが生成したものではありません。

自分用に調整する

要件を自分の基準に合わせて編集し、結果をチェックしましょう。プロンプトアナライザーは入力に合わせて再採点し、オプティマイザーは要件を落とさずに冗長な表現を削り、セキュリティスキャナーはモデルに送る前に秘密情報や個人データを検出します。

その他のカテゴリ