senrecep/csharpessentials/csharpessentials-clone

Claude Code and agent skill by senrecep/csharpessentials

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when entities need deep-copy semantics. Implement ICloneable<T> on domain objects, then call .Clone() on IEnumerable<T> or IQueryable<T> collections to produce independent deep copies of every element.

Install

npx vskill@latest install senrecep/csharpessentials/csharpessentials-clone

SKILL.md

CSharpEssentials.Clone

Typed deep-copy contract for domain objects. ICloneable<T> is covariant and type-safe, unlike System.ICloneable which returns object.

Installation

bash
dotnet add package CSharpEssentials.Clone

Namespace

csharp
using CSharpEssentials.Clone;

Implement ICloneable\<T\>

csharp
public class Product : ICloneable<Product>
{
public int Id { get; init; }
public string Name { get; init; } = "";
public List<Tag> Tags { get; init; } = new();
public Product Clone() => new()
{
Id = Id,
Name = Name,
Tags = Tags.Select(t => t.Clone()).ToList() // deep-copy child collections too
};
}
public class Tag : ICloneable<Tag>
{
public string Value { get; init; } = "";
public Tag Clone() => new() { Value = Value };
}

Clone Collections

Extension methods call Clone() on every element:

csharp
List<Product> products = [new() { Id = 1, Name = "Pen" }];
// IEnumerable<T> where T : ICloneable<T>: lazily clones each element
IEnumerable<Product> copies = products.Clone();
// IQueryable<T> where T : ICloneable<T>: clones in memory, not translated to SQL
IQueryable<Product> projected = products.AsQueryable().Clone();

Typical Use Case

Snapshot EF Core results before applying in-memory transformations, without mutating tracked entities:

csharp
List<Product> snapshot = await db.Products
.Where(p => p.Name.StartsWith("P"))
.ToListAsync();
List<Product> working = snapshot.Clone().ToList(); // independent deep copies; mutations don't affect EF tracking

Best Practices

  • Always deep-copy nested collections inside Clone(); a shallow copy defeats the purpose
  • ICloneable<T> is covariant (out T): a Product : ICloneable<Product> is also an ICloneable<object>
  • Clone() on a sequence is lazy; call ToList() to materialize the copies once
  • Consider using record types with with expressions for immutable value objects instead of ICloneable<T>
  • ICloneable<T> is most valuable for mutable domain objects that are tracked by EF Core

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
27
Repository forks
1
7-day trend score
22

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/senrecep/csharpessentials/csharpessentials-clone/badge)](https://verified-skill.com/skills/senrecep/csharpessentials/csharpessentials-clone)

Something wrong with this skill or its page? Tell us.