From 189ba4a10e5f693de16cd520513d3bbe84c2b4f6 Mon Sep 17 00:00:00 2001 From: BeeTwin Date: Thu, 5 Sep 2024 22:21:53 +0400 Subject: [PATCH] docs: documentation for enum from/to string naming strategies --- docs/docs/configuration/enum.mdx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/docs/configuration/enum.mdx b/docs/docs/configuration/enum.mdx index 067bde498a3..2f4bbaa594e 100644 --- a/docs/docs/configuration/enum.mdx +++ b/docs/docs/configuration/enum.mdx @@ -21,6 +21,16 @@ 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. | + @@ -28,7 +38,7 @@ The `IgnoreCase` property allows to opt in for case insensitive mappings (defaul ```csharp // highlight-start - [Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true)] + [Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true, EnumNamingStrategy = EnumNamingStrategy.SnakeCase)] // highlight-end public partial class CarMapper { @@ -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); } ```