Skip to content

Commit

Permalink
docs: documentation for enum from/to string naming strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
BeeTwin committed Sep 5, 2024
1 parent f3d70e4 commit 189ba4a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion docs/docs/configuration/enum.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ Available strategies:

The `IgnoreCase` property allows to opt in for case insensitive mappings (defaults to `false`).

Enum from/to strings mappings can be customized by setting the enum naming strategy to be used.
You can specify the naming strategy using `NamingStrategy` in `MapEnumAttribute` or `MapperAttribute`.
Available naming strategies:

| Name | Description |
| -----------| ------------------------------------------------|
| PascalCase | Matches enum values using PascalCase. (default) |
| SnakeCase | Matches enum values using snake_case. |
| KebabCase | Matches enum values using kebab-case. |

<Tabs>
<TabItem value="global" label="Global (mapper level)" default>

Applied to all enums mapped inside this mapper.

```csharp
// highlight-start
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true)]
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true, EnumNamingStrategy = EnumNamingStrategy.SnakeCase)]
// highlight-end
public partial class CarMapper
{
Expand All @@ -50,6 +60,11 @@ The `IgnoreCase` property allows to opt in for case insensitive mappings (defaul
[MapEnum(EnumMappingStrategy.ByName, IgnoreCase = true)]
// highlight-end
public partial CarMakeDto MapMake(CarMake make);

// highlight-start
[MapEnum(EnumMappingStrategy.ByName, NamingStrategy = EnumNamingStrategy.SnakeCase)]
// highlight-end
public partial MyEnum FromString(string source);
}
```

Expand Down

0 comments on commit 189ba4a

Please sign in to comment.