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

2 AutoCtor

3 AutoDeconstruct

4 ConstructorGenerator

5 PrimaryParameter

6 QuickConstructor

7 sourcedepend

See category

Constructor