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);
}
}

Usefull

Download Example (.NET C# )

Share AutoDeconstruct

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

In the same category (Constructor) - 6 other generators

AutoConstructor

AutoCtor

ConstructorGenerator

PrimaryParameter

QuickConstructor

sourcedepend