migrate-static-to-wrapper
Fungsinya
Skill ini memindahkan kode C# dari pemanggilan statis langsung, seperti membaca waktu saat ini atau file, ke pembungkus yang diinjeksi atau abstraksi bawaan. Skill ini untuk pengembang yang ingin membuat kode bisa diuji dalam langkah kecil yang terkendali.
Kapan dipakai
- βSaat Anda ingin mengganti DateTime.UtcNow atau DateTime.Now dengan TimeProvider di proyek.
- βSaat pemanggilan File langsung sebaiknya pindah ke pembungkus sistem file yang sudah ada di satu namespace.
- βSaat sebuah kelas membutuhkan injeksi constructor untuk abstraksi baru dan pengujiannya butuh versi palsu.
Link skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-test/skills/migrate-static-to-wrapper/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βGanti pemanggilan DateTime.UtcNow langsung di proyek Orders saya dengan TimeProvider, dan perbarui pengujian agar memakai jam palsu.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Agent membatasi pekerjaan pada cakupan yang Anda sebutkan, mengubah pemanggilan dan constructor agar memakai abstraksi yang diinjeksi, lalu memperbarui pengujian terkait dengan versi palsu.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Migrate Static to Wrapper
Perform mechanical, codemod-style replacement of static dependency call sites with calls to injected wrapper interfaces or built-in abstractions. Operates on a bounded scope (single file, project, or namespace) so migrations can be done incrementally.
When to Use
- After wrappers have been generated (via
generate-testability-wrappers) or built-in abstractions identified - Migrating
DateTime.UtcNowβTimeProvider.GetUtcNow()across a project - Migrating
File.*βIFileSystem.File.*across a namespace - Adding constructor injection for the new abstraction to affected classes
- Making a
staticutility class testable by adding an ambient seam (Step 3) while its existing call sites keep compiling unchanged - Incremental migration: one project or namespace at a time
- Updating affected tests with fakes when the requested migration names the replacement abstraction
When Not to Use
- No wrapper or abstraction exists yet and one must be designed from scratch (use
generate-testability-wrappersfirst). A built-in abstraction such asTimeProviderorIFileSystemalways counts as existing. - The user wants to detect statics, not migrate them (use
detect-static-dependencies) - Migrating between test frameworks (use the appropriate migration skill)
- The user primarily asks for a deterministic behavior test and has not selected
the production seam (use
testability-obstacle)
A class that is
static, or a project with no DI container, is not a reason to skip this skill β that is exactly what the ambient seam in Step 3 is for. Use it whenever the call sites must keep compiling unchanged.
Inputs
| Input | Required | Description |
|---|---|---|
| Static pattern | No | Infer from the request and discovered call sites (e.g., DateTime.UtcNow, File.ReadAllText) |
| Replacement abstraction | No | Infer from the request and existing project abstractions; stop only when no named/existing abstraction is available |
| Scope | No | Infer from the requested file/project/namespace, otherwise discover the narrowest relevant workspace scope |
| Injection strategy | No | constructor (default), primary-constructor, or ambient |
Workflow
Non-negotiable migration boundaries
- Missing abstraction means stop. If the named interface/package is absent and the request only authorizes call-site replacement, do not add a package, invent a local lookalike interface, or edit production code. Report the exact missing prerequisite and the authorization needed to continue.
- One source read stays one replacement read. Do not hoist or coalesce calls, even when sharing a captured timestamp looks cleaner.
- The requested scope is exhaustive and exclusive. Replace every named call in scope and no adjacent member or file.
- Repository-backed requests require repository work. Start by discovering files from the current workspace. Do not claim the repository is unavailable or ask the user for a path or file contents until workspace-relative discovery found no target. Do not say work was implemented unless the diff proves it.
- Discovered workspace files must be completed in this turn when permitted.
Use a host-native shell reader (
sed/catorGet-Content) only after a confirmed reader availability, transport, or path-normalization failure and only after verifying the canonical path remains inside the current workspace. Stop on content-exclusion, permission/policy, workspace-boundary, or unknown read failures. Use a shell edit fallback only for a confirmed editor availability, transport, or path-normalization failure, never for a stale context, concurrent change, permission/policy denial, or path-boundary error. Before fallback, resolve the canonical path inside the current workspace, freshly read the file, and require an anchored replacement with the expected old text and exact match count; abort if either changed. Then re-open the file, inspect the diff, and validate. Do not ask the user to paste a readable discovered file or report a proposed patch as completed work.
Step 1: Verify prerequisites
Before modifying any code:
- Confirm the wrapper/abstraction exists: Check that the interface or built-in abstraction is available in the project. For
TimeProvider, verify the target framework is .NET 8+ orMicrosoft.Bcl.TimeProvideris referenced. ForSystem.IO.Abstractions, v
Pertanyaan umum
Apakah skill ini juga membuat pembungkusnya?
Tidak. Jika belum ada pembungkus, skill generate testability wrappers harus membuatnya lebih dulu.
Bisakah saya mengerjakan seluruh solusi sekaligus?
Skill bekerja pada cakupan terbatas, seperti satu file, proyek, atau namespace, sehingga perubahan bisa dilakukan bertahap.
Apakah skill ini hanya mencari pemanggilan statis?
Tidak. Pencarian dilakukan skill deteksi terpisah, sedangkan skill ini melakukan penggantiannya.
Detail
Deskripsi asli dari pembuat
ALWAYS USE when asked to migrate, replace, or make testable existing C# static calls with a named wrapper or built-in abstraction: DateTime.UtcNow/Now or DateTimeOffset.UtcNow to TimeProvider/IClock, File.* to IFileSystem or an existing store such as ITextFileStore, and Environment.* to an existing reader such as IEnvironmentReader. Covers scoped files/projects, constructor injection, replacing temp-file or process-environment tests with fakes, "already registered" abstractions, and static classes whose callers/signatures must stay unchanged. Preserves DateTimeKind and call count. DO NOT USE f
repo: dotnet/skills
Popularitas
- Bintang GitHub
- 5.8k
- Peringkat
- #14632
- Lisensi
- MIT
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
create-custom-agent
5.8kMembantu agent Anda membuat file agen kustom VS Code dengan alatnya sendiri, instruksi, dan serah terima ke agent lain.
create-skill
5.8kMembantu agent Anda membuat skill agent baru dengan nama yang valid, deskripsi pemicu yang jelas, dan file SKILL.md yang mengikuti standar.
csharp-scripts
5.8kMembantu agent Anda menjalankan program C# kecil sebagai satu file dengan alat baris perintah .NET, tanpa membuat proyek lengkap.
dotnet-pinvoke
5.8kMembantu agent Anda memanggil pustaka native C atau C++ dari .NET dengan benar, mencakup tanda tangan, penanganan string, memori, dan safe handle.
Skill serupa
test-driven-development
311kMengajari agent Anda menulis tes yang gagal dulu, melihatnya gagal, lalu menulis kode terkecil yang lulus, sebelum membangun fitur atau perbaikan apa pun.
verification-before-completion
311kMengajari agent Anda menjalankan pemeriksaan nyata dan membaca keluarannya sebelum menyatakan tugas, perbaikan, atau build sudah selesai atau lulus.
migrate-to-shoehorn
310kMengganti type cast berisiko di file tes Anda dengan pustaka shoehorn, sehingga tes bisa memakai data parsial dan tetap lulus pemeriksaan tipe.