forked from riok/mapperly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Include all members of nested member
Fixes riok#453
- Loading branch information
Rhodon
committed
Apr 22, 2024
1 parent
3390769
commit eb5e2a9
Showing
25 changed files
with
530 additions
and
43 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Riok.Mapperly.Abstractions/MapNestedPropertiesAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Riok.Mapperly.Abstractions; | ||
|
||
/// <summary> | ||
/// Maps all properties from a nested path on the source to the root of the target. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] | ||
[Conditional("MAPPERLY_ABSTRACTIONS_SCOPE_RUNTIME")] | ||
public sealed class MapNestedPropertiesAttribute : Attribute | ||
{ | ||
private const string PropertyAccessSeparatorStr = "."; | ||
private const char PropertyAccessSeparator = '.'; | ||
|
||
/// <summary> | ||
/// Maps all members of the specified source property to the root of the target. | ||
/// </summary> | ||
/// <param name="source"> | ||
/// The name of the source property that will be flattened. The use of `nameof()` is encouraged. A path can be specified by joining property names with a '.'. | ||
/// </param> | ||
public MapNestedPropertiesAttribute(string source) | ||
: this(source.Split(PropertyAccessSeparator)) { } | ||
|
||
/// <summary> | ||
/// Maps all members of the specified source property to the root of the target. | ||
/// </summary> | ||
/// <param name="source">The path of the source property that will be flattened. The use of `nameof()` is encouraged.</param> | ||
public MapNestedPropertiesAttribute(string[] source) | ||
{ | ||
Source = source; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the source property to flatten. | ||
/// </summary> | ||
public IReadOnlyCollection<string> Source { get; } | ||
|
||
/// <summary> | ||
/// Gets the full name of the source property path to flatten. | ||
/// </summary> | ||
public string SourceFullName => string.Join(PropertyAccessSeparatorStr, Source); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Riok.Mapperly/Configuration/NestedMembersMappingConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Riok.Mapperly.Configuration; | ||
|
||
public record NestedMembersMappingConfiguration(StringMemberPath Source); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.