/dotnet:codingfrom dotnet
Use when writing or reviewing C#, covering functional design with result and effect types
Ships in dotnet. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Covers C# design from signature shape to host boundary, with LanguageExt and Thinktecture types as vocabulary.
[REFERENCES]:
Function signatures are contracts, input types describe every value the function accepts and the return type every outcome the caller must handle. Arrow notation writes () for no input or no returned information and a tuple for grouped inputs, the delegate states the signature in code:
| [INDEX] | [PURPOSE] | [ARROW_NOTATION] | [DELEGATE] |
|---|---|---|---|
| [01] | Transform a value | int -> string | Func<int, string> |
| [02] | Produce a value | () -> string | Func<string> |
| [03] | Consume a value for effects | int -> () | Action<int> |
| [04] | Perform an effect | () -> () | Action |
| [05] | Combine inputs | (int, int) -> int | Func<int, int, int> |
| [06] | Accept a function | (string, (IDbConnection -> R)) -> R | Func<string, Func<IDbConnection, R>, R> |
Func and Action for delegate valuesref, out, in, params, and pointer parameters, one per signature, or names telling same-typed parameters apartextension(<receiver>) block per receiver with its type parameters, constraints, and ref or in in place of thisFunc field, property, or factoryfun gives an inline lambda its delegate typeWhere and TakeWhile share one), names state itPath.ChangeExtension(file, ".tmp"))Functions honor their signature when each declared input produces a declared output, they return no null and throw no exception as an outcome the signature omits. Correct a dishonest contract by narrowing the input to a validated type or widening the output to Option<A> or Fin<A>:
int -> Tier is incomplete when some integers fail validation, and Quantity -> Tier is accurate for every constructible Quantitystring -> int hides the undefined parses, string -> Option<int> describes every outcome, and parseInt has that signatureUnit removes the void split between Func and Action and between Task and Task<T>, void stays on an imperative APIfun converts an Action into a Func<Unit>, and an Action overload delegates to the Func<T> implementation through itUnit does not make an effectful function pureUnit arithmetic or a discard ternary spelling them as a value? appears only where an external representation requires it, Optional converts it to Option<A> there"" gets it from one Option<string> conversion!, a cast of an object? result, and ValueUnsafe on a value element are unchecked escapes, Optional lifts the nullable result into the outcome that names its failureFunctions are pure when their return value depends only on their inputs (immutable values fixed at construction included) and evaluation causes no side effect, a pure call's result replaces the call (referential transparency). Side effects are mutating state visible outside the function (instance fields included), mutating an argument, throwing, and I/O (clock, console, filesystem, database, network, or another process). Instance methods that read mutable fields and lambdas that close over mutable variables are impure, mutation local to a function that never escapes is no side effect. Pure functions are safe for parallel evaluation, lazy evaluation, and memoization. Expose a variable dependency as input data, clock and reader's culture enter as arguments in place of ambient clock and culture:
internal static class Stamps {
public static string Format(Instant now, CultureInfo culture, string label) => string.Create(culture, $"{now} - {label}");
}
Pure methods can be static, every value they need is an argument or immutable, and a static method reads no mutable static field and performs no I/O a caller cannot replace.
Higher-order functions accept a function, return one, or both, and a delegate is the function value. The higher-order function owns the stable control flow and the caller supplies the varying rule: Filter owns iteration and the caller owns the inclusion criterion, IfNone(Func<T>) owns the cache miss and the caller owns the fallback work. Closures combine a lambda with its declaring context, the declared signature stays unary and the computation reads the captured values beside its argument:
Seq<DayOfWeek> days = toSeq(Enum.GetValues<DayOfWeek>());
Seq<DayOfWeek> StartingWith(string prefix) => days.Filter(day => day.ToString().StartsWith(prefix, StringComparison.Ordinal));
Seq<DayOfWeek> matched = StartingWith("S");
Function factories turn configuration into behavior. compose(f, g) joins functions into one function that applies f first (method groups need its explicit type arguments), method chaining expresses the same flow inline:
internal static class Factories {
public static Func<int, bool> IsMod(int divisor) => value => value % divisor is 0;
public static Seq<int> MultiplesOfThree => toSeq(Range(1, 20)).Filter(IsMod(3));
}
Currying turns a function of N arguments into N unary functions (curry), partial application (par) fixes leading arguments and returns a function of the rest. Order parameters for left-to-right application: dependencies and configuration known at composition root, then policies that select behavior, then the runtime value. Dependencies are functions describing behavior a consumer needs: a clock is a TimeProvider, a validator T -> Fin<T>, a lookup Guid -> Eff<RT, Option<T>>, and persistence T -> IO<Unit>. Composition roots read configuration, adapt infrastructure into dependency functions, partially apply dependencies and policies, and inject only specialized functions into handlers. I/O calls make every delegating layer above them impure.
Select the form by the call site:
ForAll or Exists when a short-circuiting boolean sufficesExpressions evaluate to values, and statements perform an action or control execution. Loops, calls made only for side effects, and branches that direct mutation are statements, and a conditional with alternatives that both return a value is an expression. Build a returned object in one expression that defines each property at creation, and extract a calculation into a function when it obscures the construction:
internal static class Projections {
public static Output Make(Input input) =>
new() {
Total = input.Unit * input.Count,
Label = input.Alternate ? input.FirstChoice : input.SecondChoice,
};
}
Prefer a query over a mutable accumulator, a named reduction (Min(seed), Max(seed)) over a Fold that restates it, Fold with a seed for any other reduction, and indexed Map over a declared counter. One-arm x switch { var y => … } bindings stay for a value an expression reads more than once or inside a lambda, and a binding read once or never is inlined.
Declarations state their type once, where it adds a fact: a local names its type and the value takes it from the target (new(), [], default), and var stays in patterns. Text that differs by case is one expression choosing between complete values (flag ? "Saved" : "Unsaved", or a switch expression), never a fragment spliced in or a statement per branch.
Pattern matching selects a result from a value's type, shape, or properties, and keeps recognition, extraction, guards, and results together, where procedural type checks need casts and nested branches and virtual methods spread one rule across classes:
internal abstract record Entry(decimal Amount, decimal Rate);
internal sealed record TieredEntry(decimal Amount, decimal Rate, decimal Bonus) : Entry(Amount, Rate);
internal sealed record ClosedEntry(decimal Amount, decimal Rate) : Entry(Amount, Rate);
internal static class Rates {
public static decimal Apply(Entry entry) =>
entry switch {
TieredEntry { Amount: > 20_000m } tiered => tiered.Amount * (tiered.Rate + (tiered.Bonus * 1.25m)),
TieredEntry { Amount: > 10_000m and <= 20_000m } tiered => tiered.Amount * (tiered.Rate + tiered.Bonus),
ClosedEntry => 0m,
_ => entry.Amount * entry.Rate,
};
}
Each arm states an input category beside its outcome, and the switch expression forms a function body or a Func passed to a higher-order function. Pattern forms:
{ Parent.Name: "root" }) inspect nested data without extracting each intermediate object>, and, not) express ranges and exclusions inside a patternwhen adds a guard, _ is the discard for the fallback armPatterns can invoke getters, indexers, and Deconstruct with unspecified evaluation order. Keep those members pure, and decode fallible input into Option<A> or a closed union before matching.
Tuples group related values without inventing a type that has no independent meaning, and named elements hold lookup results together between Map operations on a Seq<A> until the next projection consumes them:
internal static class Report {
public static Seq<string> Render(Seq<int> ids, Func<int, Item> getItem, Func<int, Seq<string>> getTags) =>
ids
.Map(id => (Item: getItem(id), Tags: getTags(id)))
.Map(static x => $"{x.Item.Name}: {string.Join(", ", x.Tags)}");
}
Recursive functions need a base case that returns the final value, a recursive case that calls the same function with values closer to that condition, and a returned value on every path. C# does not optimize tail calls, the depth bound and successor sharing select the form:
| [INDEX] | [APPROACH] | [USE_WHEN] | [COST] |
|---|---|---|---|
| [01] | Direct recursion | Maximum depth small and bounded | Unbounded calls grow the stack |
| [02] | Trampoline<A> | Pure transition, unbounded depth | Every step is a deferred call |
| [03] | Monad.recur | Effectful transition, only the final value needed | Intermediate states are lost |
| [04] | LanguageExt.List.unfold | Intermediate states are meaningful and compose as a Seq<A> | Each unfold call reruns the transition |
| [05] | Graph traversal | Shared or cyclic successors (dependencies, references) | Graph built before the walk |
Graphs build once into a read-only graph a record holds, successor functions walk as implicit graphs, and cyclic graphs order through their condensation with each cycle as one component. Recursive unions with children no other parent holds keep the union fold.
Immutable values are fixed once created, a needed change derives a new value from existing values, and a state transition is a function that receives the old state and the information the change needs and returns the replacement. Language features constrain reassignment:
readonly protects the fields and not the objects reached through theminit accessors permit object-initializer syntax and prevent reassignment after initializationrequired marks a property that cannot be omitted, optional parts are init members or defaulted parameters in place of a positional Nonerecord supports nondestructive mutation through with, which copies the unchanged properties and leaves the original unchangedstruct only for a native call, package API (parallel action), or JIT-specialized generic kernelinternal sealed record Document {
public required string Title { get; init; }
public required string Author { get; init; }
public Seq<string> Tags { get; init; }
}
internal static class Editions {
public static Document Retitled(Document document, string suffix) => document with { Title = $"{document.Title} {suffix}" };
}
None of readonly, init, and with makes a referenced child object immutable, immutability extends through every referenced value:
Seq<A>, copy a mutable input collection at the boundary with toSeq, and keep element types immutableLens<A, B> with lens(outer, inner) updates a nested field without a chain of with expressionsList<T> or Dictionary<K, V> stays inside a scope that publishes an immutable valuenew(source) { ... })In-place updates (List<T>.Sort()) destroy the prior value, transformations preserve it and values keeps its order:
Seq<int> values = Seq(7, 6, 1);
Seq<int> sorted = toSeq(values.Order());
Concurrent reorders of a shared list during a sum give readers an inconsistent traversal, a separate ordered view removes interference. Choose collections by their most frequent operation: Seq<A> for ordered reads, Lst<A> for indexed edits, Map<K, V> or HashMap<K, V> for keyed lookups successors update, FrozenDictionary<K, V> for a table built once and only read, Set<A> or HashSet<A> for uniqueness, and Iterable<A> for a lazy source.
Every function returns an explicit result type, and one type serves one concern:
| [INDEX] | [TYPE] | [CONCERN] |
|---|---|---|
| [01] | Option<A> | Absence without an Error |
| [02] | Fin<A> | Expected failure, Bind stops, Apply joins |
| [03] | Either<L, R> | Value of either type, neither an error |
| [04] | Validation<F, A> | Failures of a monoid F other than Error |
| [05] | Try<A> | Synchronous exception capture, deferred |
| [06] | IO<A> | Side effects with a failure channel |
| [07] | Eff<RT, A> | Effects that read a capability |
Input boundaries select the result type, functions preserve it, and conversions happen at one named boundary through the method named for the target (ToFin, ToOption, ToSeq). Match, Run, RunSafe, IfNone, and IfFail are host operations. Values of A and Error lift into Fin<A> by implicit conversion, Pure(x) and Fail<Error>(e) make the lift explicit where no target type fixes the result (a var local, an inferred type argument), and a Unit or Error in a position that fixes Fin converts alone. An empty Seq<A> is a result and not absence, Option<Seq<A>> exists only where the consumer responds differently to no collection and to an empty one. A producer that maps an operational failure to None hides the failure from the consumer.
Give each step a function and select the operator by the step's signature and by whether the steps depend on each other:
| [INDEX] | [SIGNATURE] | [OPERATOR] | [BEHAVIOR] |
|---|---|---|---|
| [01] | T -> R | Map | Transforms a present value and preserves the result type |
| [02] | T -> bool | Filter on Option, guard on Fin | Keeps a value only when it passes, guard names the error |
| [03] | T -> F<R> | Bind, one from per step in LINQ | Continues with a dependent step, the first failure stops it |
| [04] | (F<A>, F<B>) independent | Tuple Apply | Joins every error under Fin, overlaps under IO |
| [05] | Seq<A> with A -> F<B> | Traverse, TraverseM | Traverse accumulates or overlaps, TraverseM stops first |
| [06] | T -> void | Iter | Performs the terminal effect only for a present value |
Bind calls become a query when an inner step reads the callback value, an inner step reading nothing bound moves to the outer chainfrom clauses that select returns unchanged become select <value> over the earlier stepsIO<Option<A>>) stay nested, the consumer matches the inner Option once and no chain binds through it with a transformerinternal static class Workflow {
public static Fin<Account> Handle(Command command, Account state) =>
from normalized in Pure(Normalize(command)).ToFin()
from _ in Fault.Unless(IsValid(normalized), Reason.Invalid, normalized)
from next in state.Transition(normalized.Amount)
select next;
}
Expected failures are data in return types, and exceptions signal developer defects, initialization failures, or third-party calls a boundary converts with IO.lift or Try.lift. Each raising package declares one reason smart enum of its domain reasons, and one Fault<TReason> record every package shares, an Expected over IFaultReason, holds the rejected value as subject, the reason, and optional index and cause. Message derives every fault's text from its subject and reason in one place, subject first, and Create(string) holds the text a generator states with no reason. Fault.Of and Fault.Unless infer the reason type, and call sites pass typed values and spell no phrase:
[SmartEnum]
public sealed partial class Reason : IFaultReason {
public static readonly Reason Invalid = new("rule violated");
public static readonly Reason Missing = new("missing");
public string Message { get; }
}
internal static class Accounts {
public static Fin<Account> Found(Option<Account> found, Guid id) => found.ToFin(Fault.Of(Reason.Missing, id));
public static Fin<Unit> Funded(decimal balance, decimal amount) => Fault.Unless(balance >= amount, Reason.Invalid, (balance, amount));
}
Consumers classify an error by type with IsType<E> and Filter<E>, and a captured exception with HasException<E>. LanguageExt's Errors.Cancelled, Errors.TimedOut, Errors.Closed, and Errors.ParseError stand for those failures. A thrown exception stays the Exceptional the lift captured, and a boundary wraps it only to add a subject it lacks (a path), through Catch on its HasException<E> into an error that keeps the exception as its cause. Fin<A> holds violated business rules, IO<A> holds technical work and captures a thrown exception as Exceptional. Hosts separate both in one Match, IsExceptional logs detail and renders a generic failure, every other error renders its business message.
Host calls signaling failure with bool, -1, or null become Fin at the call (store.Write(file) ? unit : Error.New(...)), and a failed step the caller continues past keeps its error message in the outcome.
Subjects are a value or a tuple of values ((slot, content.Id)), a helper taking a delegate names its caller through [CallerMemberName] and [CallerLineNumber], and each reason item states its wording once. Keys and captions read their member symbol (nameof), values print through their type's formatter under a culture argument, and text no host shows goes. Library faults name what failed and why, and the plug-in or command layer adds the remedy and localizes a caption once where it is declared.
Use dotnet:thinktecture for value type validation.
Model each valid state a consumer inspects as a distinct case. States differing only by a tag are one record keyed by a smart enum item holding the data consumers read. Special values of one formula are one record of its parameters. Counting values a type has (a product multiplies its fields' counts, Option<A> adds one) exposes unneeded states:
[Union]
internal abstract partial record Shape {
public double Area => Switch(
circle: static circle => double.Pi * circle.Radius * circle.Radius,
rectangle: static rectangle => rectangle.Width * rectangle.Height);
internal sealed record Circle(double Radius) : Shape;
internal sealed record Rectangle(double Width, double Height) : Shape;
}
Switch only where behavior depends on the case, and pass the union onward elsewhereSeq of the base typeOption, Fin, or Either otherwiseTrampoline<A>| [INDEX] | [WRONG_FORM] | [CORRECT_FORM] |
|---|---|---|
| [01] | Match in the middle of a pipeline unwraps a value the next step relifts | Bind the next step |
| [02] | IfNone with an arbitrary default hides absence | ToFin with an Error |
| [03] | Matching on message text couples the consumer to prose | IsType<E> or Filter<E> |
| [04] | OptionT<IO, A> or a match per step over an Option inside an effect | IO<Option<A>> matched once by its consumer |
| [05] | Fin, Either<Error, A>, Validation, or Try inside an effect | Expected on IO, ValidationT<Error, IO, A> accumulates |
| [06] | Run inside a pipeline performs the effect before the host runs it | Keep the IO and Bind the next step |
| [07] | Some as a null guard | Optional at the null boundary |
| [08] | Separate result and error fields, or default on failure | One result type with mutually exclusive cases |
| [09] | Fields present together or meaningful under one flag | One Option of a record or one union case |
| [10] | Union case that extends a sibling case | Sibling cases with their own data |
| [11] | from chain or ToValidation round trip over independent checks | Tuple Apply or Traverse over Fin checks |
IO<A> describes a side effect with a failure channel, performs nothing until the host runs it, and holds a rejection as an Expected on that channel in place of a nested result:
IO.lift defers a thunk, IO.lift(Fin<A>) puts an evaluated rejection on the channelIO.liftAsync adapts a task thunk, its EnvIO overload passes env.TokenIO.liftAsync and have no synchronous counterpart that blocks a threadIO.pure and IO.fail build the plain casesEff<RT, A> reads a capability from a runtime RT through Has<Eff<RT>, T>, IO<A> converts to it implicitlyHost runs the effect once, RunSafe() returns the Fin<A> for translation into the host's vocabulary, and Run throws and belongs to Main:
internal static class Host {
public static int Exit(IO<Unit> handler) =>
handler.RunSafe().Match(
Succ: static _ => 0,
Fail: static error => error.IsExpected ? 4 : 1);
}
Inject the narrowest dependency that represents what consumers need: a value for a stable snapshot, an IO<A> for an operation that must run on demand, a runtime RT for a consumer that reads many capabilities, and one interface resolved once for a seam each platform implements in full. Clocks behind an interface leave consumers impure, an injected date makes a consumer deterministic:
internal static class Validators {
public static Func<Command, Fin<Command>> NotPast(LocalDate today) =>
command => Fault.Unless(command.Date >= today, Reason.Invalid, command.Date).Map(_ => command);
}
Hosts read the date once from a TimeProvider argument (time.ToZonedClock().GetCurrentDate()). Request handling supplies each command's date later. TimeProvider supplies elapsed time through GetTimestamp() and GetElapsedTime(start).ToDuration(), each read inside its consuming IO, and the composition root alone names TimeProvider.System. Duration compares and scales as a value (a - b < step * n) and is the one time type model fields hold, a TimeSpan, tick, or second count appears only at an API taking one. Hosts log through ILogger with [LoggerMessage] members from one LoggerFactory per session, a sink interface over (Error, Type, string) restates it. Pair acquisition and release through use, closing its resource scope with Bracket(). Release functions return void or IO<Unit>, a commit follows successful work outside release.
Failure policies are distinct operations:
primary | secondary, or primary | @catch(predicate, f) for one error classRetry(Schedule.exponential(delay) | Schedule.recurs(attempts))IfFail on the Fin<A>Libraries return their result type with their own errors, the application composes the retry schedule, the fallback order, and the cache around it, and the host logs only a failure that reaches its translation. Traversals beyond the composition operators take a concurrency bound or keep every failure:
| [INDEX] | [SCENARIO] | [TRAVERSAL] | [BEHAVIOR] |
|---|---|---|---|
| [01] | Bounded concurrency | Chunk, then TraverseM over the chunks | One chunk at a time, the chunk width sets the bound |
| [02] | Every effect, failures kept | PartitionFallible | Serial, no short-circuit, returns Fails and Succs |
Keep state unshared, and when one logical value must be shared, serialize its changes:
Atom<A> replaces the value with compare-and-swapAtomHashMap<K, V> holds a registry with FindOrAddRef<A> under atomic commits coordinated updatesConduit reduced under Fork serializes commands as an agentDelivery shape selects the construct:
Source<A> fits values that arrive over time, logic across events or sources (sequences, transitions, windows), and one-way dataflowFin<A> values inside the streamIO<A>, request-response work stays out of a streamConduit as the queue or Pipes as the pipelineNumeric facts come from the package that states them. Sample loops read only spans and SIMD lanes, with Matrix<double>, quantities, and BigInteger outside the loop:
TryFindRoot receives a signed margin, bracket, caller accuracy, and iteration limit, a missed root stays a typed failurelong or Int128, a shift for the cell and a mask for the local partLength and Angle name parameters, bounds, and presentation units, a float holds samples and a host unit scale enters once at the boundary| [INDEX] | [FACT] | [MEMBER] |
|---|---|---|
| [01] | Scalar root | Bisection.TryFindRoot |
| [02] | Quadrature | Integrate.GaussKronrod |
| [03] | Spline | CubicSpline.InterpolatePchipSorted |
| [04] | Fit | Fit.Polynomial |
| [05] | Quantile | SortedArrayStatistics.Quantile |
| [06] | Factorization | Matrix<double>.Svd |
| [07] | Antiderivative | Polynomial.Integrate |
dotnet:memory for spans, pooled buffers, 2D views, parallel passes, and span kernelsdotnet:ui for drawn surfaces, shaped text, vector art, color, and host controlsreferences/analyzers.md (opens in a new tab)references/effects.md (opens in a new tab)references/event-sourcing.md (opens in a new tab)references/functions.md (opens in a new tab)references/immutable-data.md (opens in a new tab)references/interop.md (opens in a new tab)references/language-features.md (opens in a new tab)references/results.md (opens in a new tab)references/sequences.md (opens in a new tab)references/state.md (opens in a new tab)references/streams.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub bsamiee/rasm --plugin dotnet8 skills in this plugin
/codelensUse when reading, diagnosing, or refactoring a file in a .NET solution, covering the roslyn-codelens MCP server/debuggingUse when C# or another CoreCLR program misbehaves at runtime and its cause is unproven (wrong value, failing test, exception, hang, crash, breakpoint that never stops), covering DNCDbg launches and attaches, held starts, test runners, PDB documents, exception stops, expressions, live process reads, and dumps/languageextUse when calling a LanguageExt member/mapperlyUse when writing or reviewing a Mapperly mapper, covering mapping at the host boundary/memoryUse when writing or reviewing C# over spans, memory, or pooled buffers, covering ownership, views, kernels, lanes, parallel passes, and binary formats/thinktectureUse when declaring a Thinktecture type or fixing a TTRESG diagnostic, covering generated API and framework integration