Agent skill

Ref Struct Delegates

by corvus-dotnet in corvus-dotnet/Corvus.JsonSchema

Replace Func< and Action< with custom delegate types when any parameter or return type is a ref struct (Span<T, ReadOnlySpan<T, etc.).

Apache-2.0Auto-check passed

Install Ref Struct Delegates

skills CLI
$ npx skills add corvus-dotnet/Corvus.JsonSchema --skill ref-struct-delegates -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install corvus-dotnet/Corvus.JsonSchema ref-struct-delegates --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/corvus-dotnet/Corvus.JsonSchema.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/ref-struct-delegates .claude/skills/ref-struct-delegates && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
ref-struct-delegates
GitHub stars
199
Token cost
~1.3k tokens
SKILL.md length
294 words
Files
1
Skills in repo
26
Repo updated
First seen
Licence
Apache-2.0

At a glance

Replace Func< and Action< with custom delegate types when any parameter or return type is a ref struct (Span<T, ReadOnlySpan<T, etc.).

  • Works in 3 steps: Identify the offending Func/Action → Create a named delegate with the same… → Replace all usages
  • : writing public APIs that accept callbacks involving spans
  • SKILL.md covers The Problem, The Fix: Named Delegates, Translation Rules and Convenience Factory Pattern, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Ref Struct Delegates is an agent skill from corvus-dotnet/Corvus.JsonSchema. Replace Func< and Action< with custom delegate types when any parameter or return type is a ref struct (Span<T, ReadOnlySpan<T, etc.). Ref structs cannot appear as generic type arguments, so Func<ReadOnlySpan<byte, bool is a compile error. The fix is a named delegate. USE FOR: writing public APIs that accept callbacks involving spans, storing span-accepting lambdas in fields, wrapping IJsonPathFunction or similar interfaces with delegate-based factories. DO NOT USE FOR: APIs where all parameters are regular…

Its SKILL.md is about 1.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

The repository describes itself as: Support for Json Schema validation and entity generation. The licence is Apache-2.0.

When your agent uses it

  • : writing public APIs that accept callbacks involving spans
  • Storing span-accepting lambdas in fields
  • Wrapping IJsonPathFunction
  • Similar interfaces with delegate-based factories

Example prompts

  • “/ref-struct-delegates”

Workflow steps

3 steps, taken from the step headings in SKILL.md.

  1. Identify the offending Func/Action
  2. Create a named delegate with the same shape
  3. Replace all usages

What it can do on your machine

Read from SKILL.md and the folder at commit b9e3040. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are csharp).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Ref Struct Delegates loads about 1.3k tokens when it runs. Until then it costs about 150 tokens; SKILL.md has 294 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~150
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from corvus-dotnet/Corvus.JsonSchema at commit b9e3040, republished under its Apache-2.0 licence (© corvus-dotnet). 294 words, ~1,302 tokens.

Download SKILL.mdSave it as .claude/skills/ref-struct-delegates/SKILL.md (or your agent's skills folder).
name
ref-struct-delegates
description
Replace Func<> and Action<> with custom delegate types when any parameter or return type is a ref struct (Span<T>, ReadOnlySpan<T>, etc.). Ref structs cannot appear as generic type arguments, so Func<ReadOnlySpan<byte>, bool> is a compile error. The fix is a named delegate. USE FOR: writing public APIs that accept callbacks involving spans, storing span-accepting lambdas in fields, wrapping IJsonPathFunction or similar interfaces with delegate-based factories. DO NOT USE FOR: APIs where all parameters are regular (non-ref-struct) types — plain Func<>/Action<> is fine there.

Ref Struct Delegate Translation

The Problem

Func<>, Action<>, and Predicate<> are generic types. C# forbids ref structs (Span<T>, ReadOnlySpan<T>, ReadOnlyMemory<T>.Span, etc.) as generic type arguments. This means:

csharp
// ❌ COMPILE ERROR — ReadOnlySpan<T> is a ref struct
Func<ReadOnlySpan<byte>, bool> predicate;
Action<Span<char>> writer;
Func<ReadOnlySpan<JsonPathFunctionArgument>, JsonWorkspace, JsonPathFunctionResult> evaluator;

The Fix: Named Delegates

Define a named delegate type with the ref struct parameter directly:

csharp
// ✅ COMPILES — named delegates can have ref struct parameters
public delegate bool SpanPredicate(ReadOnlySpan<byte> data);
public delegate void SpanWriter(Span<char> buffer);
public delegate JsonPathFunctionResult JsonPathFunctionEvaluator(
    ReadOnlySpan<JsonPathFunctionArgument> arguments,
    JsonWorkspace workspace);

Translation Rules

1. Identify the offending Func/Action

Find every Func<> or Action<> where any type argument is a ref struct.

2. Create a named delegate with the same shape
Original (broken)Replacement
Func<ReadOnlySpan<T>, TResult>delegate TResult MyDelegate(ReadOnlySpan<T> items);
Func<ReadOnlySpan<T>, TOther, TResult>delegate TResult MyDelegate(ReadOnlySpan<T> items, TOther other);
Action<Span<T>>delegate void MyDelegate(Span<T> buffer);
Predicate<ReadOnlySpan<T>>delegate bool MyDelegate(ReadOnlySpan<T> items);
3. Replace all usages

Fields, parameters, locals, and lambda assignments all change from the Func<>/Action<> type to the named delegate. Lambda syntax remains identical — only the declared type changes:

csharp
// Before (broken):
Func<ReadOnlySpan<byte>, int, bool> check = (span, len) => span.Length >= len;

// After (works):
public delegate bool SpanCheck(ReadOnlySpan<byte> span, int minLength);
SpanCheck check = (span, len) => span.Length >= len;

Convenience Factory Pattern

When building factory methods that wrap lambdas into an interface (e.g. IJsonPathFunction), split the API into two tiers:

  1. Convenience overloads — use Func<> with non-ref-struct projections of the data (e.g. copy ReadOnlySpan<T> to T[] before passing to the delegate):
csharp
// Nodes are copied to an array so Func<> works
public static IJsonPathFunction NodesValue(
    Func<JsonElement[], JsonWorkspace, JsonElement> func)
    => new DelegateFunction(
        JsonPathFunctionType.ValueType,
        [JsonPathFunctionType.NodesType],
        (args, ws) => JsonPathFunctionResult.FromValue(
            func(args[0].Nodes.ToArray(), ws)));
  1. Full-control overload — use the named delegate for zero-copy access:
csharp
public delegate JsonPathFunctionResult JsonPathFunctionEvaluator(
    ReadOnlySpan<JsonPathFunctionArgument> arguments,
    JsonWorkspace workspace);

public static IJsonPathFunction Create(
    JsonPathFunctionType returnType,
    JsonPathFunctionType[] parameterTypes,
    JsonPathFunctionEvaluator evaluate)
    => new DelegateFunction(returnType, parameterTypes, evaluate);

This gives callers a choice: simple lambda with a small allocation (Func<T[], ...>) or zero-allocation with the named delegate.

Storing the Delegate in a Field

Named delegates are regular reference types and can be stored in fields, unlike the ref structs they accept:

csharp
private sealed class DelegateFunction : IJsonPathFunction
{
    private readonly JsonPathFunctionEvaluator evaluate; // ✅ field storage works

    public DelegateFunction(JsonPathFunctionEvaluator evaluate)
    {
        this.evaluate = evaluate;
    }

    public JsonPathFunctionResult Evaluate(
        ReadOnlySpan<JsonPathFunctionArgument> arguments,
        JsonWorkspace workspace)
        => this.evaluate(arguments, workspace);
}

Naming Convention

Name the delegate after its purpose, not its shape. Good names describe what the callback does:

✅ Good❌ Bad
JsonPathFunctionEvaluatorSpanFuncDelegate
SpanPredicateReadOnlySpanBoolFunc
BufferWriterSpanAction

Scope

This applies to all ref struct types, not just spans:

  • Span<T>, ReadOnlySpan<T>
  • Custom ref struct types in the codebase
  • Any future ref struct added by .NET

Cross-References

  • For the stackalloc/ArrayPool rent pattern that produces spans, see corvus-buffer-and-pooling
  • For ref-struct collections in this codebase, see corvus-low-alloc-data-structures

© corvus-dotnet, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/ref-struct-delegates of corvus-dotnet/Corvus.JsonSchema.

Open the folder on GitHubat commit b9e3040

Compare with similar skills

Ref Struct Delegates next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Ref Struct Delegates compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Ref Struct Delegates this skillcorvus-dotnet/Corvus.JsonSchema199—~1.3kAutomated safety check: PassApache-2.0
Fp Types Refsickn33/agentic-awesome-skills47k2 repos~583Automated safety check: PassMIT
Rust Path Typesopeninterpreter/openinterpreter69k2 repos~605Automated safety check: PassApache-2.0
Python Type Safetywshobson/agents40k—~1.4kAutomated safety check: PassMIT
ActionsJetBrains/intellij-community21k—~341Automated safety check: PassCustom licence
Pyrefly Type Coveragepytorch/pytorch104k—~3kAutomated safety check: PassCustom licence

Similar skills

  • Fp Types Ref

    sickn33/agentic-awesome-skills

    Quick reference for fp-ts types. An agent skill from sickn33/agentic-awesome-skills.

    47k GitHub starsUsed in 2 repos~583 tokens
    Auto-check passed
  • Rust Path Types

    openinterpreter/openinterpreter

    Rules for choosing Rust types for filesystem paths in new Codex code, covering protocol types, internal use and model tool arguments.

    69k GitHub starsUsed in 2 repos~605 tokens
    DevelopmentAuto-check passed
  • Python Type Safety

    wshobson/agents

    Python type safety with type hints, generics, protocols, and strict type checking.

    40k GitHub stars~1.4k tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • Actions

    JetBrains/intellij-community

    Official

    Implement or change IntelliJ AnAction actions and registrations.

    21k GitHub stars~341 tokensUpdated today
    MobileAuto-check passed
  • Pyrefly Type Coverage

    pytorch/pytorch

    Migrate a file to use stricter Pyrefly type checking with annotations required for all functions, classes, and attributes.

    104k GitHub stars~3k tokensUpdated today
    DevelopmentAuto-check passed
  • Laravel Actions

    coollabsio/coolify

    Build, refactor, and troubleshoot Laravel Actions using lorisleiva/laravel-actions.

    63k GitHub stars~2.4k tokensUpdated today
    Backend & APIsAuto-check passed

More from corvus-dotnet/Corvus.JsonSchema

All 26 skills in this repo
  • Corvus Analyzers

    corvus-dotnet/Corvus.JsonSchema

    Understand and work with the Roslyn analyzers shipped with Corvus.Text.Json.

    199 GitHub stars~876 tokensUpdated today
    Auto-check passed
  • Corvus Benchmarks

    corvus-dotnet/Corvus.JsonSchema

    Run, interpret, and maintain BenchmarkDotNet benchmarks for JSON Schema validation and query languages.

    199 GitHub stars~1.2k tokensUpdated today
    Auto-check passed
  • Corvus Bowtie Testing

    corvus-dotnet/Corvus.JsonSchema

    Test Corvus.JsonSchema against the JSON Schema Test Suite using Bowtie, the cross-implementation meta-validator.

    199 GitHub stars~1.4k tokensUpdated today
    Auto-check passed
  • Corvus Buffer And Pooling

    corvus-dotnet/Corvus.JsonSchema

    Write allocation-efficient buffer code in Corvus.JsonSchema using the codebase's established three-tier pooling pattern: stackalloc → ArrayPool → ThreadStatic caches.

    199 GitHub stars~2.9k tokensUpdated today
    Auto-check passed
  • Corvus Bytes To Bytes

    corvus-dotnet/Corvus.JsonSchema

    Eliminate hand-rolled POCO record<-document string seams — types/paths that materialize a managed string (or List<string/Dictionary) between a bytes SOURCE (a parsed UTF-8 body, a DB column, a…

    199 GitHub stars~3k tokensUpdated today
    Auto-check passed
  • Corvus Codegen

    corvus-dotnet/Corvus.JsonSchema

    Generate strongly-typed C from JSON Schema using the Roslyn source generator or the corvusjson CLI tool.

    199 GitHub stars~2.1k tokensUpdated today
    Auto-check passed

Questions about Ref Struct Delegates

What does Ref Struct Delegates do?

Replace Func< and Action< with custom delegate types when any parameter or return type is a ref struct (Span<T, ReadOnlySpan<T, etc.). JsonSchema.).

When should I use Ref Struct Delegates?

Ref Struct Delegates fits situations like: : writing public APIs that accept callbacks involving spans; storing span-accepting lambdas in fields; wrapping IJsonPathFunction; similar interfaces with delegate-based factories.

How do I install Ref Struct Delegates in Claude Code?

Run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill ref-struct-delegates -a claude-code`. Or copy the skill folder (.github/skills/ref-struct-delegates in corvus-dotnet/Corvus.JsonSchema) into .claude/skills/ref-struct-delegates in your project. Claude Code loads it when a task matches its description.

How do I install Ref Struct Delegates in Codex?

Run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill ref-struct-delegates -a codex`. Or copy the skill folder (.github/skills/ref-struct-delegates in corvus-dotnet/Corvus.JsonSchema) into .agents/skills/ref-struct-delegates in your project. Codex loads it when a task matches its description.

Can I use Ref Struct Delegates in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill ref-struct-delegates -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/ref-struct-delegates, .gemini/skills/ref-struct-delegates, .github/skills/ref-struct-delegates and .opencode/skills/ref-struct-delegates in your project.

What does Ref Struct Delegates need to run?

SKILL.md names no scripts, command-line tools or credentials: Ref Struct Delegates is instructions for the agent only.

Does Ref Struct Delegates access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Ref Struct Delegates safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Ref Struct Delegates use?

Ref Struct Delegates is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Ref Struct Delegates use?

About 1.3k tokens (SKILL.md is roughly 5.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Ref Struct Delegates?

Skills that share tags, products or a category with Ref Struct Delegates: Fp Types Ref (sickn33/agentic-awesome-skills, 47k stars), Rust Path Types (openinterpreter/openinterpreter, 69k stars), Python Type Safety (wshobson/agents, 40k stars) and Actions (JetBrains/intellij-community, 21k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Ref Struct Delegates?

corvus-dotnet (a GitHub organization) maintains it in corvus-dotnet/Corvus.JsonSchema, which has 199 GitHub stars. The repository holds 26 skills in this directory. The repository was last updated on October 8, 2026.

Source: corvus-dotnet/Corvus.JsonSchema on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.