Skip to main content

AutoDeconstruct by Jason Bock

NuGet / site data​

Nuget GitHub last commit GitHub Repo stars

Details​

Info​

info

Name: AutoDeconstruct

Generates deconstruction methods for type definitions.

Author: Jason Bock

NuGet: https://www.nuget.org/packages/AutoDeconstruct

You can find more details at https://github.com/JasonBock/AutoDeconstruct/blob/main/docs/Overview.md

Source: https://github.com/jasonbock/autodeconstruct

Original Readme​

note

AutoDeconstruct

A library that automatically adds support for object deconstruction in C#.

Overview​

The idea started with this tweet - specifically, this reply. I thought...how automatic can I make object deconstruction in C#? That's what this source generator is all about.

Read the overview document for further details.

About​

note

Automatically add deconstruct for all types in an assembly

How to use​

Example (source csproj, source files)​

This is the CSharp Project that references AutoDeconstruct

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoDeconstruct" Version="1.0.0" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>

Generated Files​

Those are taken from $(BaseIntermediateOutputPath)\GX

#nullable enable

public static partial class PersonExtensions
{
public static void Deconstruct(this global::Person @self, out string? @firstName, out string? @lastName, out string? @title)
{
global::System.ArgumentNullException.ThrowIfNull(@self);
(@firstName, @lastName, @title) =
(@self.FirstName, @self.LastName, @self.Title);
}
}

Useful​

Download Example (.NET C#)​

Share AutoDeconstruct​

https://ignatandrei.github.io/RSCG_Examples/v2/docs/AutoDeconstruct

aaa

Category "Constructor" has the following generators:​

1 AutoConstructor Nuget GitHub Repo stars 2023-10-28

2 AutoCtor Nuget GitHub Repo stars 2023-04-16

3 AutoDeconstruct Nuget GitHub Repo stars 2023-04-16

4 ConstructorGenerator Nuget GitHub Repo stars 2024-12-07

5 PrimaryParameter Nuget GitHub Repo stars 2023-11-15

6 QuickConstructor Nuget GitHub Repo stars 2023-04-16

7 sourcedepend Nuget GitHub Repo stars 2024-02-16

See category​

Constructor