AGENT SKILL

csharp-refactoring

Refactor C# and reconcile stale constants, dead checks and abandoned code, including indirect production uses. Use for renames, moves, deduplication, exhaustive cleanup, generated declarations and runtime/API contracts. MSTest test design and review belong to mstest-extensions.

License 许可
Apache-2.0
最近更新
2026-11-10
Stars
★ 1
Forks
0

01 前言 Front Matter

name
csharp-refactoring
license
Apache-2.0
description
Refactor C# and reconcile stale constants, dead checks and abandoned code, including indirect production uses. Use for renames, moves, deduplication, exhaustive cleanup, generated declarations and runtime/API contracts. MSTest test design and review belong to mstest-extensions.

02 资源文件 2

03 SKILL.md 正文

C# refactoring

Process

  1. Map the change. Find the declaration, binding references, generator inputs and affected TFMs or #if branches. Identify which contracts must stay stable and which changes the user authorized. A compile-clean rename alone does not establish compatibility with runtime consumers.
  2. Edit the owner. Prefer IDE/Roslyn rename or compiler-checked binding edits. Include partial declarations; change generator inputs rather than generated output. Extract shared behavior toward its existing owner, preserving each caller's inputs, evaluation order and side effects.
  3. Verify the boundary. Use the repository's affected build/test entrypoint for each changed target. Reuse its compilation evidence instead of building twice. Check the runtime contracts below when touched; report unverified branches explicitly. Keep authorized behavior changes distinct from the mechanical refactor without refusing the rest of the task.

Contracts the compiler cannot settle

Boundary Check
Serialization, configuration, reflection, DI or dynamic Names may be data. Preserve external names through existing metadata, or migrate their consumers when that change is authorized.
Public API, nullable annotations, parameter names Include source/binary compatibility and named arguments; check the repository's API record when present.
Type moved between assemblies A same-name move may need TypeForwardedTo in the original assembly; a rename needs a different compatibility decision.
Generated/partial code, friends, conditional builds Follow generator ownership, InternalsVisibleTo, all declarations and each affected compilation.
Wrapper removal or type merge Retain compatibility adapters only for a real consumer boundary. Remove internal dead indirection once its callers are migrated.

A CLR rename can preserve an existing JSON field through explicit metadata:

[JsonPropertyName("request_id")]
public required string RequestId { get; init; }

Keep request_id when only the CLR name changes; verify the wire contract through its actual serializer or generated metadata.

Constants and abandoned code

For exhaustive cleanup, use constant reconciliation. Account for every declaration in scope, including retained and unresolved items; do not stop at an easy deletion shortlist. When runtime cost is in scope, invoke ancplua-dotnet:performance for measurements. MSTest implementation/verification uses mstest-extensions:mstest; targeted assertion fixes use mstest-extensions:mstest-assertions. Package/framework upgrades use ancplua-dotnet:nuget-versions. Invoke only an available skill for the requested part; report a missing specialist and preserve the remaining refactoring scope.

04 同仓库更多 Skills

ANcpLua
ANcpLua/ancplua-dotnet

csharp-union-types

Design, review and implement C# 15 unions and closed hierarchies in .NET 11 code. Use for union declarations, custom [Union] types, exhaustive matching, default/null handling and union serialization. Do not upgrade earlier frameworks or replace working inheritance merely because unions exist.

★ 1
ANcpLua
ANcpLua/ancplua-dotnet

release

Releases .NET NuGet packages through a layered chain (library, MSBuild SDK, analyzers, consumers) without breaking restore. Use when publishing a package, bumping a lower-layer dependency in its consumers, moving a .NET SDK pin across repositories, choosing tag-driven versus push-driven publishing, setting up NuGet trusted publishing, or waiting for nuget.org to index a version before consumers restore it.

★ 1
ANcpLua
ANcpLua/ancplua-dotnet

performance

Investigate .NET runtime performance using logs, metrics, traces, spans and profiles; collect crash/hang diagnostics. Use for CPU, GC, allocation or latency problems, hot-path reviews and BenchmarkDotNet comparisons. MSBuild timing belongs to msbuild; MSTest execution belongs to mstest-extensions.

★ 1
ANcpLua
ANcpLua/ancplua-dotnet

nuget-versions

Manage .NET package and SDK versions, CPM migrations, Version.props ownership, global.json pins, isolated SDK installations and Renovate updates. Use for package bumps, conflicting or missing versions, NuGet restore errors and SDK selection. MSTest runner/profile semantics belong to mstest-extensions.

★ 1
ANcpLua
ANcpLua/ancplua-dotnet

msbuild

Writes and reviews MSBuild evaluation, properties, items, imports, custom targets and build/buildTransitive package assets for SDK-style .NET repositories. Use for ignored or empty properties/items, generated files, analyzer/build-asset packaging, build-file reviews, binlog diagnosis and incremental-build problems. Focused MSTest project setup, runner configuration and test commands belong to mstest-extensions.

★ 1
ANcpLua
ANcpLua/ancplua-dotnet

audit

Audits one or more .NET repositories for build, package and analyzer problems and separates certain fixes from judgment calls. Use for repository or fleet build-policy audits, shared SDK/package consistency and cross-repository version rollouts. Focused MSTest setup, execution and test-quality reviews belong to mstest-extensions.

★ 1