UtilityVerse.Copy 0.6.0

dotnet add package UtilityVerse.Copy --version 0.6.0
                    
NuGet\Install-Package UtilityVerse.Copy -Version 0.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UtilityVerse.Copy" Version="0.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UtilityVerse.Copy" Version="0.6.0" />
                    
Directory.Packages.props
<PackageReference Include="UtilityVerse.Copy" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add UtilityVerse.Copy --version 0.6.0
                    
#r "nuget: UtilityVerse.Copy, 0.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package UtilityVerse.Copy@0.6.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=UtilityVerse.Copy&version=0.6.0
                    
Install as a Cake Addin
#tool nuget:?package=UtilityVerse.Copy&version=0.6.0
                    
Install as a Cake Tool

UtilityVerse.Copy

<img src="https://raw.githubusercontent.com/purkayasta/TheUtilityVerse/development/src/UtilityVerse.Copy/Assets/copy.png" alt="UtilityVerse.Copy icon" width="64" height="64">

UtilityVerse.Copy NuGet version UtilityVerse.Copy total downloads

Generate DeepCopy() and ShallowCopy() methods for partial C# classes, records, structs, and record structs. Opt in with attributes or empty marker interfaces.

Get started

dotnet add package UtilityVerse.Copy
using UtilityVerse.Copy;

[DeepCopy]
public partial class Node
{
    public string? Name { get; set; }
    public Node? Next { get; set; }
}

// Call source.DeepCopy() to copy the graph.

Use [ShallowCopy] for an outer copy that shares references. Request both modes to generate both methods. Interface consumers can use IDeepCopy and IShallowCopy.

Depth and stack safety

Depth defaults to 5, with the root at level 1. Each new model or container adds one level. Scalars, nulls, and already-copied references add no level.

  • Attribute configuration uses [DeepCopy(depth: 10)].
  • Interface configuration uses [CopyDepth(10)] with IDeepCopy.
  • Valid values are 1–100. Invalid values produce UV006 and use 5.
  • The root's budget applies to the entire operation. Exceeding it throws NotSupportedException and clears partial copy state.

Execution-stack checks and internal-operation limits remain active. Raising the depth limit still depends on available stack space. An independent 100-level compiler traversal guard reports excessive type nesting through UV004. Existing consumers copying deeper graphs need explicit configuration and rebuilt generated code.

What it copies

Deep copies preserve supported stored fields and auto-properties, shared reference identity, mutable cycles, runtime derived types, and collection comparers. Arrays, lists, dictionaries, tuples, queues, stacks, and selected immutable and frozen collections are supported. Stack<T> preserves LIFO order, and Queue<T> preserves FIFO order. Member policies can share, reset, or use an external copier.

The compiler reports unsupported declarations and stored shapes. Some runtime values also require registration or a custom copier. The full guide documents collection restrictions, inheritance, framework requirements, and diagnostic fixes. Read the Copy guide

Requirements

Requires Roslyn 4.11+, available with .NET SDK 8.0.400+ or Visual Studio 2022 17.11+. The package targets .NET Standard 2.0 and supplies the runtime graph context used by generated code. Retain its runtime package reference. Copying uses typed generated assignments without runtime model-member reflection or external runtime dependencies.

Runnable examples

The package includes examples.md at its root with complete programs and expected behavior for consumers and coding agents. Browse examples

Why .NET Standard 2.0?

The generator runs inside compiler and IDE hosts. A .NET Standard 2.0 target keeps it loadable by compatible .NET Framework hosts. The consumer project can target modern .NET. Feature-specific generated code follows the consumer's available APIs.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.0 107 11/27/2026
0.5.0 421 7/19/2025
0.4.0 189 7/19/2025
0.3.0 252 7/15/2025
0.2.1 247 6/29/2025
0.2.0 344 6/29/2025 0.2.0 is deprecated because it has critical bugs.
0.1.1 277 6/27/2025 0.1.1 is deprecated because it has critical bugs.
0.1.0 214 6/27/2025 0.1.0 is deprecated because it has critical bugs.