-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to disable specific conversions (#213)
- Loading branch information
Showing
25 changed files
with
355 additions
and
16 deletions.
There are no files selected for viewing
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,31 @@ | ||
# Conversions | ||
|
||
Mapperly implements several types of automatic conversions. | ||
A list of conversions supported by Mapperly is available [here](../api/riok.mapperly.abstractions.mappingconversiontype#fields). | ||
|
||
## Disable all automatic conversions | ||
|
||
To disable all conversions supported by Mapperly set `EnabledConversions` to `None`: | ||
```csharp | ||
// highlight-start | ||
[Mapper(EnabledConversions = MappingConversionType.None)] | ||
// highlight-end | ||
public partial class CarMapper | ||
{ | ||
... | ||
} | ||
``` | ||
|
||
## Disable specific automatic conversions | ||
|
||
To disable a specific conversion type, set `EnabledConversions` to `All` excluding the conversion type to disable: | ||
```csharp | ||
// this disables conversions using the ToString() method: | ||
// highlight-start | ||
[Mapper(EnabledConversions = MappingConversionType.All & ~MappingConversionType.ToStringMethod)] | ||
// highlight-end | ||
public partial class CarMapper | ||
{ | ||
... | ||
} | ||
``` |
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
namespace Riok.Mapperly.Abstractions; | ||
|
||
/// <summary> | ||
/// A <see cref="MappingConversionType"/> represents a type of conversion | ||
/// how one type can be converted into another. | ||
/// </summary> | ||
[Flags] | ||
public enum MappingConversionType | ||
{ | ||
/// <summary> | ||
/// None. | ||
/// </summary> | ||
None = 0, | ||
|
||
/// <summary> | ||
/// Use the constructor of the target type, | ||
/// which accepts the source type as a single parameter. | ||
/// </summary> | ||
Constructor = 1 << 0, | ||
|
||
/// <summary> | ||
/// An implicit cast from the source type to the target type. | ||
/// </summary> | ||
ImplicitCast = 1 << 1, | ||
|
||
/// <summary> | ||
/// An explicit cast from the source type to the target type. | ||
/// </summary> | ||
ExplicitCast = 1 << 2, | ||
|
||
/// <summary> | ||
/// If the source type is a <see cref="string"/>, | ||
/// uses a a static visible method named `Parse` on the target type | ||
/// with a return type equal to the target type and a string as single parameter. | ||
/// </summary> | ||
ParseMethod = 1 << 3, | ||
|
||
/// <summary> | ||
/// If the target type is a <see cref="string"/>, | ||
/// uses the `ToString` method on the source type. | ||
/// </summary> | ||
ToStringMethod = 1 << 4, | ||
|
||
/// <summary> | ||
/// If the target is an <see cref="Enum"/> | ||
/// and the source is a <see cref="string"/>, | ||
/// parses the string to match the name of an enum member. | ||
/// </summary> | ||
StringToEnum = 1 << 5, | ||
|
||
/// <summary> | ||
/// If the source is an <see cref="Enum"/> | ||
/// and the target is a <see cref="string"/>, | ||
/// uses the name of the enum member to convert it to a string. | ||
/// </summary> | ||
EnumToString = 1 << 6, | ||
|
||
/// <summary> | ||
/// If the source is an <see cref="Enum"/> | ||
/// and the target is another <see cref="Enum"/>, | ||
/// map it according to the <see cref="EnumMappingStrategy"/>. | ||
/// </summary> | ||
EnumToEnum = 1 << 7, | ||
|
||
/// <summary> | ||
/// Enables all supported conversions. | ||
/// </summary> | ||
All = ~None, | ||
} |
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
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
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.