SuperAPI AI Directory

csharp-code-review

Testing & quality

View repository

Updated 10-15 20:05

About this skill

C# Code Review Skill

Systematically review C# code from the perspectives of OOP principles, SOLID principles, GoF design patterns, modern C# features, and performance.

Important: All review results must be written in Korean. Code identifiers, technical terms, pattern names, etc. should be kept as-is in the original, while descriptive parts such as explanations, issues, and improvement suggestions should use Korean.

Arguments

  • $ARGUMENTS[0]: Target file or directory path (optional; if unspecified, search for the most recently modified .cs file)

Execution Steps

Step 1: Identify review target

If the user does not specify a file:

  • Most recently modified .cs file check
  • Or request the user to specify the file/directory to review

Step 2: Code analysis

Read the target code and analyze it from the perspectives below.

Review Checklist

4 OOP Principles

Principle Review items
Encapsulation Private fields, property access, hiding implementation details
Inheritance Appropriate inheritance hierarchy, prefer composition over inheritance
Polymorphism Use of interfaces/abstract classes, appropriateness of virtual methods
Abstraction Appropriate level of abstraction, unnecessary exposure of details

SOLID Principles

Principle Review items Signs of violation
SRP Does the class have a single responsibility? Class changes for multiple reasons, too many methods
OCP Is it open for extension and closed for modification? Existing code must be modified when adding new features, switch/if-else chains
LSP Can subtypes substitute for supertypes? Exceptions thrown in subclasses, empty method overrides
ISP Are interfaces separated for each client? NotImplementedException, unused methods
DIP Does it depend on abstractions? Direct instantiation with new, dependency on concrete class types

Opportunities to apply GoF design patterns

Identify parts of the code where the following patterns can be applied:

Creational patterns

  • Complex object creation → Builder
  • Separating object creation logic → Factory Method / Abstract Factory
  • Global single instance → Singleton (Caution: do not overuse)

Structural patterns

  • Connecting incompatible interfaces → Adapter
  • Adding dynamic functionality → Decorator
  • Simplifying complex subsystems → Facade
  • Object tree structure → Composite

Behavioral patterns

  • Replaceable algorithms → Strategy
  • Changing behavior based on state → State
  • Communication between objects → Observer / Mediator
  • Request handling chain → Chain of Responsibility
  • Undo/Redo → Command + Memento

Latest C# Features (C# 12/13)

Feature Recommended When
Primary constructors Classes with simple initialization
Collection expressions Array/list initialization [1, 2, 3]
required properties Guarantee required initialization without a constructor
init-only setters Immutable objects
record types Value-based equality, DTO
Pattern matching Complex conditionals, type checks
File-scoped namespaces Reduced indentation
Raw string literals Multi-line strings, JSON, SQL

Performance review

Category Review item
Memory allocation Unnecessary allocations on hot paths, Large Object Heap (>= 85KB)
Async/Await Blocking calls (.Result, .Wait()), missing ConfigureAwait
Collections Incorrect collection type, multiple LINQ enumeration
Strings String concatenation in loops, StringBuilder not used
Boxing Unnecessary value type boxing
Span/Memory Buffer operations without Span, Memory

Async code review

  • .Result or .Wait() no calls (deadlock risk)
  • in library code ConfigureAwait(false) usage
  • Proper CancellationToken propagation
  • on hot paths with cached results ValueTask usage
  • for streaming data IAsyncEnumerable usage
  • No async void except event handlers

Code quality review

  • Naming conventions (PascalCase, camelCase, _privateField, Async suffix)
  • Null safety (nullable reference types, ?., ??, ??=)
  • Exception handling (specific exceptions, when filters, appropriate logging)
  • IDisposable pattern compliance (using statements, Dispose implementation)
  • Collection usage (appropriate type selection, efficient LINQ)
  • Declare magic numbers/strings as constants
  • Remove duplicate code
  • On classes that don't need inheritance, sealed use appropriately

Security review

  • Input validation (SQL Injection, XSS, path traversal)
  • Sensitive data handling (no hardcoded secrets, appropriate encryption)
  • Authentication/authorization verification
  • Secure random number generation (Random not for security purposes)
  • XML External Entity (XXE) prevention

Step 3: Output review results

Output format

All content is written in Korean. Code identifiers and technical terms are kept in their original form.

# 코드 리뷰 결과

## 요약
- 파일: {파일 경로}
- 종합 평가: {우수/양호/개선 필요/심각}
- 주요 이슈: {N}건
- .NET 버전 준수: {.NET 8/9 기능 활용도}

## SOLID 원칙 분석

### SRP 위반 (심각도: 높음/보통/낮음)
- 위치: `ClassName.cs:line`
- 문제: {설명}
- 개선안: {코드 예시 포함}

### OCP 위반
...

## 최신 C# 기능 적용 기회

### {기능명} 권장
- 위치: `file.cs:line`
- 현재: {기존 코드}
- 개선: {최신 C# 문법}
- 이점: {설명}

## 성능 이슈

### {이슈 제목} (심각도: 높음/보통/낮음)
- 위치: `file.cs:line`
- 문제: {영향 포함 설명}
- 현재: {문제 코드}
- 개선: {최적화 코드}
- 효과: {예상 개선점}

## 비동기 코드 이슈

### {이슈 제목}
- 위치: `file.cs:line`
- 문제: {설명}
- 위험: {데드락/성능/기타}
- 해결: {코드 수정}

## 적용 가능한 디자인 패턴

### {패턴명} 패턴 권장
- 현재 코드: {문제점}
- 적용 시 이점: {설명}
- 예시 코드: {간략 예시}

## 보안 우려사항

### {이슈 제목} (심각도: 심각/높음/보통/낮음)
- 위치: `file.cs:line`
- 취약점: {설명}
- 해결: {코드 수정}

## 코드 품질 이슈

### {이슈 제목}
- 위치: `file.cs:line`
- 현재: {코드}
- 개선: {코드}

## 우선순위별 개선 사항
1. [심각] {보안 이슈}
2. [높음] {SOLID 위반, 성능 이슈}
3. [보통] {코드 품질, 최신 기능 적용}
4. [낮음] {스타일 개선}

Guidelines

  • Report only issues that need fixing. Do not include positive feedback.
  • Provide improvement suggestions with concrete code examples.
  • Do not recommend excessive engineering.
  • Make practical suggestions that consider context.
  • Treat security issues with the highest priority.
  • Suggest features considering the target .NET version.
  • Consider the balance between the latest features and team familiarity.