UtilityVerse.Copy
0.6.0
dotnet add package UtilityVerse.Copy --version 0.6.0
NuGet\Install-Package UtilityVerse.Copy -Version 0.6.0
<PackageReference Include="UtilityVerse.Copy" Version="0.6.0" />
<PackageVersion Include="UtilityVerse.Copy" Version="0.6.0" />
<PackageReference Include="UtilityVerse.Copy" />
paket add UtilityVerse.Copy --version 0.6.0
#r "nuget: UtilityVerse.Copy, 0.6.0"
#:package UtilityVerse.Copy@0.6.0
#addin nuget:?package=UtilityVerse.Copy&version=0.6.0
#tool nuget:?package=UtilityVerse.Copy&version=0.6.0
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">
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)]withIDeepCopy. - Valid values are 1–100. Invalid values produce UV006 and use 5.
- The root's budget applies to the entire operation. Exceeding it throws
NotSupportedExceptionand 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 | Versions 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. |
-
.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.