agentleFS
MovGP0MovGP0/Skills/modern-csharp/SKILL.md

modern-csharp

Skill1 starsChanged 5 months agoMITView on GitHub

Modern C# style guidance for Bendex and MicroSea code changes, including primary constructors, expression-bodied members, var usage, target-typed new, lambdas, and pattern matching.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

31 rules. About 0 are common, 26 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈26

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when writing or refactoring C# in Bendex or MicroSea projects.

    line 8
  2. Distinctive:

    Keep changes local to the feature, bug fix, or warning cleanup in progress.

    line 13
  3. Distinctive:

    Do not perform broad style-only rewrites unless the user explicitly asks for that cleanup.

    line 14
  4. Distinctive:

    Prefer the existing style in the surrounding file when it conflicts with a rule here.

    line 15
  5. Very specific:

    Do not modernize generated code, *.Designer.cs, or resource output unless the relevant specialized skill says it is safe.

    line 16
  6. Distinctive:

    Use file-scoped namespaces in new C# files.

    line 20
  7. Distinctive:

    Use primary constructors when constructor parameters are only used for initialization or dependency capture.

    line 21
  8. Very specific:

    Prefer var when the type is obvious from the right-hand side.

    line 22
  9. Very specific:

    Prefer target-typed new() when the target type is visible and readability remains clear.

    line 23
  10. Distinctive:

    Prefer object and collection initializers over repeated assignment after construction.

    line 24
  11. Distinctive:

    Prefer null-propagation, null-coalescing, and throw expressions when they make the intent clearer.

    line 25
  12. Distinctive:

    Prefer pattern matching over separate type checks and casts.

    line 26
  13. Distinctive:

    Prefer switch expressions for simple value mapping.

    line 27
  14. Distinctive:

    Prefer expression-bodied members for single-expression properties, accessors, operators, conversions, lambdas, and short local functions.

    line 28
  15. Distinctive:

    Write calls, constructors, and primary constructors with multiple arguments as a vertical argument list.

    line 30
  16. Distinctive:

    Keep Allman braces for block-bodied code, including single-line blocks.

    line 31
  17. Very specific:

    Add [DoNotPruneType] to service classes that are resolved through dependency injection.

    line 37
  18. Distinctive:

    Keep the service interface visible in the declaration instead of relying only on concrete type registration.

    line 39
  19. Distinctive:

    Use a primary constructor when it removes boilerplate without making lifetime or validation behavior less obvious.

    line 43
  20. Distinctive:

    Keep a normal constructor when:

    line 62
  21. Distinctive:

    If a constructor parameter is stored in a field because the field name improves readability, keep the field.

    line 69
  22. Distinctive:

    Write multiple arguments top-to-bottom instead of left-to-right.

    line 73
  23. Distinctive:

    Prefer expression-bodied form for one-expression members:

    line 92
  24. Distinctive:

    Keep a block body when:

    line 102
  25. Distinctive:

    When returning a newly constructed value whose type is the same as the method return type, use target-typed construction:

    line 130
  26. Distinctive:

    Avoid repeating the return type:

    line 141
  27. Distinctive:

    Check the target framework and language version before using newer syntax such as collection expressions, list patterns, required members, …

    line 154
  28. Distinctive:

    Do not change public API shape only for style.

    line 156
  29. Distinctive:

    Do not change serialization names, constructor binding, reflection behavior, dependency injection registration, or XAML/WinForms designer …

    line 157
  30. Distinctive:

    Run focused tests when behavior could have changed.

    line 162
  31. Very specific:

    Run .\BuildScripts\Update-FileLineEndings.ps1 -Git after editing files in Bendex or MicroSea repositories.

    line 163

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Modern C# style

Use this skill when writing or refactoring C# in Bendex or MicroSea projects. This skill is for intentional code style and modernization decisions. When a specific IDE* diagnostic is the trigger, also use ../ide-warnings/SKILL.md for the diagnostic-specific fix.

Scope

  • Modernize code you are already touching.
  • Keep changes local to the feature, bug fix, or warning cleanup in progress.
  • Do not perform broad style-only rewrites unless the user explicitly asks for that cleanup.
  • Prefer the existing style in the surrounding file when it conflicts with a rule here.
  • Do not modernize generated code, *.Designer.cs, or resource output unless the relevant specialized skill says it is safe.

Core rules

  • Use file-scoped namespaces in new C# files.
  • Use primary constructors when constructor parameters are only used for initialization or dependency capture.
  • Prefer var when the type is obvious from the right-hand side; keep explicit types when they improve readability or the right-hand side is not enough context.
  • Prefer target-typed new() when the target type is visible and readability remains clear.
  • Prefer object and collection initializers over repeated assignment after construction.
  • Prefer null-propagation, null-coalescing, and throw expressions when they make the intent clearer.
  • Prefer pattern matching over separate type checks and casts.
  • Prefer switch expressions for simple value mapping.
  • Prefer expression-bodied members for single-expression properties, accessors, operators, conversions, lambdas, and short local functions.
  • For ordinary methods, use an expression body only when it stays readable and does not hide important control flow.
  • Write calls, constructors, and primary constructors with multiple arguments as a vertical argument list.
  • Keep Allman braces for block-bodied code, including single-line blocks.

Services

Services in this project are commonly resolved by dependency injection and must remain visible to tooling that prunes unused types.

  • Add [DoNotPruneType] to service classes that are resolved through dependency injection.
  • Implement the service or base interface used for registration and resolution.
  • Keep the service interface visible in the declaration instead of relying only on concrete type registration.

Primary constructors

Use a primary constructor when it removes boilerplate without making lifetime or validation behavior less obvious.

Good candidates:

[DoNotPruneType]
public sealed class CustomerService(
    IRepository repository,
    ILogger<CustomerService> logger)
    : ICustomerService
{
    public Customer Load(int id)
    {
        logger.LogDebug("Loading customer {CustomerId}", id);
        return repository.Get(id);
    }
}

Keep a normal constructor when:

  • Constructor logic has meaningful branching, validation, or exception messages.
  • Several overloads delegate to one canonical constructor.
  • XML documentation on constructor parameters is important and would become less readable.
  • The type is serialized, reflected, designer-created, or framework-created and constructor shape is part of a contract.

If a constructor parameter is stored in a field because the field name improves readability, keep the field. Otherwise, use the primary constructor parameter directly.

Argument lists

Write multiple arguments top-to-bottom instead of left-to-right. This keeps diffs stable and avoids long lines.

Prefer:

var result = factory.Create(
    customerId,
    machineId,
    cancellationToken);

Avoid:

var result = factory.Create(customerId, machineId, cancellationToken);

Expression bodies and lambdas

Prefer expression-bodied form for one-expression members:

public bool IsEnabled => _settings.Enabled;

public string GetDisplayName() => $"{FirstName} {LastName}";

items.Select(item => item.Name);

Keep a block body when:

  • The body has more than one statement.
  • The expression needs comments to be understood.
  • Debugging, tracing, or exception handling is clearer with statements.
  • The expression would wrap awkwardly or obscure the domain operation.

For lambdas, prefer expression form for a single returned expression. Use a block lambda when there are multiple statements, logging, tracing, local variables, or deliberate side effects.

Implicit typing

C# methods require explicit return types. Do not invent implicit method return types. Use implicit typing for locals and lambdas where the language supports it and the result remains obvious.

Prefer:

var result = new MachineState(); // or: MachineState result = new();
Func<int, bool> isValid = value => value > 0;

Avoid:

var result = GetValue();

when GetValue() does not make the type or domain role clear.

When returning a newly constructed value whose type is the same as the method return type, use target-typed construction:

public MachineState CreateState()
{
    return new(
        machineId,
        settings);
}

Avoid repeating the return type:

public MachineState CreateState()
{
    return new MachineState(
        machineId,
        settings);
}

Compatibility boundaries

  • Check the target framework and language version before using newer syntax such as collection expressions, list patterns, required members, or raw string literals.
  • Be careful in net472 and mixed-framework projects where analyzers may allow syntax that older tooling, generators, or designers handle poorly.
  • Do not change public API shape only for style.
  • Do not change serialization names, constructor binding, reflection behavior, dependency injection registration, or XAML/WinForms designer activation as a side effect of modernization.

Verification

  • Build the smallest relevant project or solution after modernization.
  • Run focused tests when behavior could have changed.
  • Run .\BuildScripts\Update-FileLineEndings.ps1 -Git after editing files in Bendex or MicroSea repositories.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.