https://github.com/lamparter/ideconstructable
Exposes the IDeconstructable interface and its source generator to allow "deconstructing" classes into their fields.
https://github.com/lamparter/ideconstructable
constructor csharp dependencyinjection dotnet riverside riversidevalley roslyn roslyn-generator source-generator
Last synced: about 1 month ago
JSON representation
Exposes the IDeconstructable interface and its source generator to allow "deconstructing" classes into their fields.
- Host: GitHub
- URL: https://github.com/lamparter/ideconstructable
- Owner: Lamparter
- License: mit
- Created: 2025-04-02T13:54:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-02T17:03:33.000Z (about 1 year ago)
- Last Synced: 2025-10-26T02:02:08.629Z (7 months ago)
- Topics: constructor, csharp, dependencyinjection, dotnet, riverside, riversidevalley, roslyn, roslyn-generator, source-generator
- Language: C#
- Homepage: https://nuget.org/packages/Riverside.DeconstructableInterfaces
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [`Riverside.DeconstructableInterfaces`](https://nuget.org/packages/Riverside.DeconstructableInterfaces)
> Exposes the IDeconstructable interface and its source generator to allow "deconstructing" classes into their fields.
---
This library exposes an `IDeconstructable` interface that lets you 'deconstruct' classes into their fields.
For example:
```cs
public partial class MyClass : IDeconstructable
{
public MyClass()
{
Field1 = string.Empty;
Field2 = "Hello World";
}
public string Field1;
public string Field2;
}
```
This will then source generate a method in `MyClass`:
```cs
///
public partial class MyClass : IDeconstructable
{
public (string, string) Deconstruct()
=> (Field1, Field2)
}
```
This has many use cases, including:
- JSON serialisation so containing serialisation types can be split
- This might be useful when moving from reflection-based serialisation with anonymous types to source-generated serialisation
- Reducing dependency on class references or 'saving' a class's volatile data into a constant variable
..and just for fun! This project is a learning experience for making simple incremental source generators.
I came up with the idea for this when migrating [Taskie](https://github.com/shef3r/Taskie) to modern UWP with .NET 9 (on Native AOT).