agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/languages/csharp/SKILL.md

csharp

Skill15 starsChanged 42 days agoMITView on GitHub

Expert C# and .NET assistance covering LINQ, async/await patterns, pattern matching, records, Entity Framework Core, and ASP.NET Core web services. Use when writing idiomatic C#, designing .NET enterprise backends, building cross-platform services, or optimizing memory with span/memory types.

8 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use Dependency Injection & Options Pattern: Inject strongly-typed configurations via IOptions<T> and constructor injection.

    line 135
  2. Very specific:

    Use ValueTask<T> on Frequently Cached Code Paths: Reduce GC allocations by returning ValueTask when operations often complete synchronously.

    line 136
  3. Very specific:

    Use mutable shared singletons without thread safety: Use ConcurrentDictionary or proper synchronization primitives.

    line 142

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “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

C#

Modern C# development with .NET 8+, async patterns, and Entity Framework.

When to Use

  • Enterprise Web Backends & Microservices: Building high-throughput ASP.NET Core web APIs and gRPC microservices on modern .NET 8/9.
  • Cross-Platform Mobile & Desktop (MAUI): Compiling native iOS, Android, macOS, and Windows applications from a single C# codebase.
  • Cloud-Native AWS & Azure Infrastructure: Deploying scalable serverless functions, containerized workers, and event-driven apps.
  • Game Development with Unity / Godot: Developing gameplay logic, physics, and state machines in leading game engines.

Quick Start

public record User(string Id, string Name, string Email);

public class UserService
{
    public async Task<User?> GetUserAsync(string id)
    {
        return await _repository.FindByIdAsync(id);
    }
}

Core Concepts

Records & Pattern Matching (C# 12/13)

Immutable data structures with value equality and expressive switch expressions:

// Positional Record with built-in value equality
public record Order(string Id, decimal Amount, string Status);

public static class OrderClassifier
{
    public static string Evaluate(Order order) => order switch
    {
        { Status: "PAID", Amount: > 1000 } => "High-Value Order",
        { Status: "PAID" }                 => "Standard Order",
        { Status: "CANCELLED" }            => "Void Order",
        _                                  => "Pending Review"
    };
}

Memory Optimization with Span<T> and ReadOnlySpan<T>

Allocates and slices continuous memory buffers on the stack without heap GC allocations:

public static bool TryParseYear(ReadOnlySpan<char> dateSpan, out int year)
{
    // Slice without allocating new sub-strings
    ReadOnlySpan<char> yearSpan = dateSpan.Slice(0, 4);
    return int.TryParse(yearSpan, out year);
}

Async / Await with ValueTask

Efficient asynchronous programming minimizing task object allocations on hot paths:

public async ValueTask<UserProfile> GetUserProfileAsync(string userId)
{
    if (_cache.TryGetValue(userId, out var cached))
        return cached; // Synchronous return allocates zero task objects

    return await _repository.FetchFromDatabaseAsync(userId);
}

Common Patterns

Declarative Data Transformations with LINQ

Problem: Imperative nested loops and mutation when filtering, projecting, and sorting collections.

Solution:

// Query syntax
var adults = from user in users
             where user.Age >= 18
             orderby user.Name
             select user;

// Method syntax (preferred)
var result = users
    .Where(u => u.IsActive)
    .OrderBy(u => u.Name)
    .Select(u => new UserDto(u.Id, u.Name))
    .ToList();

// Grouping
var byCountry = users
    .GroupBy(u => u.Country)
    .ToDictionary(g => g.Key, g => g.ToList());

Pattern Matching

Problem: Verbose cascading conditional checks and manual type casting leading to runtime type errors.

Solution:

string GetStatus(object obj) => obj switch
{
    User { IsActive: true } => "Active user",
    User { IsActive: false } => "Inactive user",
    null => "No data",
    _ => "Unknown"
};

// List patterns
if (numbers is [var first, _, var last])
{
    Console.WriteLine($"First: {first}, Last: {last}");
}

Best Practices

Do:

  • Enable Nullable Reference Types (<Nullable>enable</Nullable>): Catch null reference exceptions at compile time across the codebase.
  • Use Dependency Injection & Options Pattern: Inject strongly-typed configurations via IOptions<T> and constructor injection.
  • Use ValueTask<T> on Frequently Cached Code Paths: Reduce GC allocations by returning ValueTask when operations often complete synchronously.
  • Leverage Native AOT Compilation: Compile .NET applications to native machine code (PublishAot=true) for sub-10ms startup and tiny memory footprints.

Don't:

  • Block async code with .Result or .Wait(): Synchronous blocking on asynchronous tasks causes immediate thread pool deadlocks.
  • Use mutable shared singletons without thread safety: Use ConcurrentDictionary or proper synchronization primitives.
  • Instantiate HttpClient per request: Use IHttpClientFactory to prevent socket exhaustion.

Troubleshooting

ErrorCauseSolution
NullReferenceExceptionAccessing nullEnable nullable, use ?.
ObjectDisposedExceptionUsing disposed resourceCheck lifetime, use using
TaskCanceledExceptionOperation cancelledHandle or propagate

References

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.