Idiomatic TypeScript patterns for clean, maintainable code.
Idiomatic patterns for clean, maintainable C# code.
PascalCase: Types, methods, properties, events, namespacescamelCase: Parameters, local variables_camelCase: Private fieldsIPascalCase: Interfaces (prefix with I)TPascalCase: Type parameters (prefix with T)IServiceCollection.ILogger<T> with structured logging. Use appropriate log levels.IOptions<T> pattern with validation. Never hardcode settings.global using for common namespaces.readonly, init, record for data integrity.static class ServiceHelper.IServiceProvider.GetService() in business logic.new() for dependencies: Inject via constructor.nameof(), constants, or configuration.// Proper DI registration
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
{
services.AddScoped<IUserService, UserService>();
services.AddScoped<IOrderService, OrderService>();
services.AddOptions<EmailSettings>()
.BindConfiguration("Email")
.ValidateDataAnnotations()
.ValidateOnStart();
return services;
}
}
// Structured logging with semantic names
public class OrderService(IOrderRepository repo, ILogger<OrderService> logger)
{
public async Task<Order?> GetOrderAsync(int orderId, CancellationToken ct)
{
logger.LogDebug("Fetching order {OrderId}", orderId);
var order = await repo.GetByIdAsync(orderId, ct);
if (order is null)
logger.LogWarning("Order {OrderId} not found", orderId);
return order;
}
}
// Options pattern with validation
public class EmailSettings
{
public const string SectionName = "Email";
[Required]
public string SmtpHost { get; init; } = string.Empty;
[Range(1, 65535)]
public int SmtpPort { get; init; } = 587;
[Required, EmailAddress]
public string FromAddress { get; init; } = string.Empty;
}
For project structure templates and DI patterns: See references/REFERENCE.md.
language | security | tooling
npx skills add ngxtm/TypeScript Best Practices下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer