一键导入
enforcing-dto-record
Force all DTO (Data Transfer Object) types to be declared as record instead of class for immutability and value-based equality.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Force all DTO (Data Transfer Object) types to be declared as record instead of class for immutability and value-based equality.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Force Regex to use GeneratedRegex Source Generator attribute instead of runtime Regex construction for compile-time optimization.
Force record instantiation via positional constructor with named arguments instead of property initializer syntax for stronger immutability expression.
Enforce branch-based workflow with meaningful Korean commits and PR creation for traceable decision history.
Force JsonSerializerOptions to be declared as static readonly or readonly fields instead of creating new instances inside methods.
Centralize external namespace imports (BCL, FCL, NuGet) in a GlobalUsings.cs file per project, keeping individual files clean.
| name | enforcing-dto-record |
| description | Force all DTO (Data Transfer Object) types to be declared as record instead of class for immutability and value-based equality. |
DTO(Data Transfer Object)는 읽기 전용(ReadOnly) 객체입니다. C#에서 class가 아닌 record로 구현해야 합니다.
record는 불변성(immutability), 값 기반 동등성(value equality), with 식을 기본 제공하므로 DTO에 최적입니다.
class 대신 record로 선언합니다sealed class + { get; set; } 패턴을 record + 위치 매개변수(positional parameter) 또는 { get; init; } 패턴으로 변환합니다// DTO를 class로 구현 - 불변성 보장 없음, 보일러플레이트 과다
private sealed class PagedResponse
{
public int Page { get; set; }
public int PageSize { get; set; }
public int TotalCount { get; set; }
public int TotalPages { get; set; }
public EmployeeDto[] Data { get; set; } = [];
}
private sealed class CreatedResponse
{
public int Count { get; set; }
public EmployeeDto[] Data { get; set; } = [];
}
private sealed class EmployeeDto
{
public string Name { get; set; } = "";
public string Email { get; set; } = "";
public string Tel { get; set; } = "";
public DateTime Joined { get; set; }
}
// JSON 역직렬화용 DTO를 class로 구현
private sealed class JsonEmployeeDto
{
public string? Name { get; set; }
public string? Email { get; set; }
public string? Tel { get; set; }
public string? Joined { get; set; }
}
// DTO를 record로 구현 - 불변성 보장, 간결한 코드
private sealed record PagedResponse(
int Page,
int PageSize,
int TotalCount,
int TotalPages,
EmployeeDto[] Data);
private sealed record CreatedResponse(
int Count,
EmployeeDto[] Data);
private sealed record EmployeeDto(
string Name,
string Email,
string Tel,
DateTime Joined);
// JSON 역직렬화용 DTO도 record로 구현
private sealed record JsonEmployeeDto(
string? Name,
string? Email,
string? Tel,
string? Joined);