Skip to content

Commit ee7818f

Browse files
committed
Update Overview.md
1 parent 0669bb3 commit ee7818f

1 file changed

Lines changed: 41 additions & 4 deletions

File tree

docs/Overview.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [What is a Deconstructor?](#what-is-a-deconstructor)
44
- [AutoDeconstruct Features](#autodeconstruct-features)
55
- [Marking Types](#marking-types)
6+
- [Filtering Properties](#filtering-properties)
67

78
## Motivation
89

@@ -122,12 +123,12 @@ namespace Models
122123
}
123124
```
124125

125-
Starting in 2.0.0, you can also declare the attribute at the assembly level:
126+
Starting in 2.0.0, you can also use `[TargetAutoDeconstruct]` at the assembly level:
126127

127128
```c#
128129
using AutoDeconstruct;
129130

130-
[assembly: AutoDeconstruct(typeof(Person))]
131+
[assembly: TargetAutoDeconstruct(typeof(Person))]
131132

132133
namespace Models;
133134

@@ -148,7 +149,7 @@ You can target other types from other assemblies if you'd like:
148149
using AutoDeconstruct;
149150
using System;
150151

151-
[assembly: AutoDeconstruct(typeof(Guid))]
152+
[assembly: TargetAutoDeconstruct(typeof(Guid))]
152153

153154
// ...
154155
var id = Guid.NewGuid();
@@ -158,4 +159,40 @@ var (variant, version) = id;
158159
Take care in creating deconstructors to types you don't own. For example, in the case of `Guid`, getting just the `Variant` and `Version` values aren't extremely helpful.
159160

160161
> [!WARNING]
161-
> If you add `[AutoDeconstruct]` to a type, and use `[TargetAutoDeconstruct]` targeting that same type, you will get a compilation error as a duplicate extension method will be made.
162+
> If you add `[AutoDeconstruct]` to a type, and use `[TargetAutoDeconstruct]` targeting that same type, you will get a compilation error as a duplicate extension method will be made.
163+
164+
### Filtering Properties
165+
166+
Starting with 3.0.0, AutoDeconstruct lets you specify properties that you want to either include or exclude in the generated `Deconstruct()` method. This is useful if you are inheriting from a type that has numerous properties that you do not want for deconstruction. Here's how it works (note that this also works with `[TargetAutoDeconstruct]`):
167+
168+
```c#
169+
using AutoDeconstruct;
170+
171+
namespace Models;
172+
173+
[AutoDeconstruct(Filtering.Include, [nameof(Person.Age), nameof(Person.Name)])]
174+
public sealed class Person
175+
{
176+
public uint Age { get; init; }
177+
public Guid Id { get; init; }
178+
public string Name { get; init; }
179+
}
180+
```
181+
182+
In this case, `Deconstruct()` will have two `out` parameters: `age` and `name`. Properties can also be excluded:
183+
184+
```c#
185+
using AutoDeconstruct;
186+
187+
namespace Models;
188+
189+
[AutoDeconstruct(Filtering.Exclude, [nameof(Person.Id)])]
190+
public sealed class Person
191+
{
192+
public uint Age { get; init; }
193+
public Guid Id { get; init; }
194+
public string Name { get; init; }
195+
}
196+
```
197+
198+
Both filtering examples lead to the same result.

0 commit comments

Comments
 (0)