askill
csharp-refactor

csharp-refactorSafety 90Repository

C# code refactoring skill. Applies SOLID principles, extracts methods/classes, introduces design patterns, and modernizes syntax. Use when improving code maintainability, addressing code smells, or modernizing legacy C# code.

7 stars
1.2k downloads
Updated 2/8/2026

Package Files

Loading files...
SKILL.md

C# Refactoring Skill

Systematically refactors C# code to improve maintainability, readability, and adherence to best practices.

Arguments

  • $ARGUMENTS[0]: Target file path (optional, will scan for .cs files if not provided)
  • $ARGUMENTS[1]: Refactor type (optional): solid, pattern, modern, extract, all

Execution Steps

Step 1: Identify Target

If no file specified ($ARGUMENTS[0] is empty):

  • Scan for recently modified .cs files
  • Ask user to select target file(s)

Step 2: Analyze Code

Read and analyze the target code for refactoring opportunities.

Step 3: Apply Refactoring

Based on $ARGUMENTS[1] or analyze all categories:

Refactoring Categories

SOLID Refactoring (solid)

ViolationRefactoring
SRPExtract class, Split responsibilities
OCPIntroduce Strategy/Template Method pattern
LSPFix inheritance hierarchy, Use composition
ISPSplit interface into smaller ones
DIPExtract interface, Inject dependencies

Pattern Introduction (pattern)

Code SmellSuggested Pattern
Complex object creationBuilder, Factory Method
Multiple conditionals on typeStrategy, State
Global state accessSingleton (cautiously), DI
Complex subsystemFacade
Tree/composite structuresComposite
Adding features dynamicallyDecorator
Request handling chainChain of Responsibility

Modern C# Syntax (modern)

Old SyntaxModern Alternative
Constructor + field assignmentPrimary constructor
new List<T> { ... }Collection expressions [...]
Multiple null checksPattern matching, ?., ??
Verbose switch statementsSwitch expressions
Manual INPC implementation[ObservableProperty] (CommunityToolkit.Mvvm)
Mutable properties (non-MVVM)required, init for immutability
Class for simple dataRecord types
Traditional foreachLINQ where appropriate

Extract Refactoring (extract)

  • Extract Method: Long methods → smaller, focused methods
  • Extract Class: Large class → multiple cohesive classes
  • Extract Interface: Concrete dependencies → interface abstraction
  • Extract Base Class: Duplicate code → shared base
  • Extract Parameter Object: Many parameters → single object

Output Format

# Refactoring Results

## Target
- File: {file_path}
- Refactor Type: {type}

## Changes Applied

### {Refactoring Name}
- Location: `file.cs:line`
- Before:
```csharp
// old code
  • After:
// refactored code
  • Benefit: {explanation}

Summary

  • Total refactorings: {N}
  • Lines changed: {N}
  • New files created: {list if any}

Recommendations

  • Further improvements that could be made
  • Related patterns to consider

## Guidelines

- Preserve existing functionality (no behavior changes)
- Make incremental changes, not massive rewrites
- Prioritize readability over cleverness
- Consider team familiarity with patterns
- Add comments only where logic is non-obvious
- Run tests after each refactoring if available

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

95/100Analyzed 2/13/2026

A highly comprehensive and well-structured C# refactoring skill. It provides clear execution steps, detailed reference tables for SOLID principles, design patterns, and modern syntax, along with specific output formatting and safety guidelines.

90
95
100
95
95

Metadata

Licenseunknown
Version-
Updated2/8/2026
PublisherNeverSight

Tags

No tags yet.