-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Ref #323
Thinking about having the ability to deconstruct objects in the constructor, without having to use an initializer.
[AutoConstruct]
public partial class TheClass
{
[AutoDeconstruct<IOptions<Config>>]
private readonly Config _config;
}
public static class Deconstructors
{
[AutoDeconstructor]
public static TConfig Deconstruct<TConfig>(IOptions<TConfig> options)
{
return options.View;
}
}Generated:
public partial class TheClass
{
public TheClass(IOptions<Config> options)
{
_config = Deconstructors.Deconstruct(options);
}
}- Only need to write the deconstructor pattern once, can be used multiple times
- What about deconstructing multiple values, e.g. tuples?
See also https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/deconstruct
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request