From b17e2c9783a6856eb5f5754d9ea7832c2ba43d9d Mon Sep 17 00:00:00 2001 From: latonz Date: Tue, 15 Oct 2024 18:59:06 +0200 Subject: [PATCH] clarify abstractions conditional scope --- docs/docs/getting-started/installation.mdx | 12 ++++++++++-- src/Riok.Mapperly.Abstractions/MapperAttribute.cs | 12 ++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/docs/getting-started/installation.mdx b/docs/docs/getting-started/installation.mdx index e5e5bca2f2..3699ce12f4 100644 --- a/docs/docs/getting-started/installation.mdx +++ b/docs/docs/getting-started/installation.mdx @@ -60,8 +60,7 @@ Checkout the latest stable version [here](https://mapperly.riok.app). ### Preserving the attributes at runtime Mapperly removes the attribute references at compile time by default (they have the `ConditionalAttribute`). -If you want -to preserve the attribute references at runtime +If you want to preserve the attribute references at runtime you can set the MSBuild variable `MapperlyAbstractionsScope` to `runtime`. ```xml @@ -74,3 +73,12 @@ you can set the MSBuild variable `MapperlyAbstractionsScope` to `runtime`. When preserving the attribute usages, the Mapperly package reference needs to include the runtime assets. Make sure `ExcludeAssets` on the `PackageReference` does not include `runtime`. ::: + +:::info +`MapperlyAbstractionsScope` only works in projects referencing `Riok.Mapperly` directly. +Alternatively you can set a constant `MAPPERLY_ABSTRACTIONS_SCOPE_RUNTIME`: +```xml + + $(DefineConstants);MAPPERLY_ABSTRACTIONS_SCOPE_RUNTIME + +::: diff --git a/src/Riok.Mapperly.Abstractions/MapperAttribute.cs b/src/Riok.Mapperly.Abstractions/MapperAttribute.cs index c3004431a7..be767cb5a5 100644 --- a/src/Riok.Mapperly.Abstractions/MapperAttribute.cs +++ b/src/Riok.Mapperly.Abstractions/MapperAttribute.cs @@ -21,6 +21,12 @@ public class MapperAttribute : Attribute /// public EnumMappingStrategy EnumMappingStrategy { get; set; } = EnumMappingStrategy.ByValue; + /// + /// Defines the strategy to use when mapping an enum from/to string. + /// Can be overwritten on specific enums via mapping method configurations. + /// + public EnumNamingStrategy EnumNamingStrategy { get; set; } = EnumNamingStrategy.MemberName; + /// /// Whether the case should be ignored for enum mappings. /// @@ -125,10 +131,4 @@ public class MapperAttribute : Attribute /// partial methods are discovered. /// public bool AutoUserMappings { get; set; } = true; - - /// - /// Defines the strategy to use when mapping an enum from/to string. - /// Can be overwritten on specific enums via mapping method configurations. - /// - public EnumNamingStrategy EnumNamingStrategy { get; set; } = EnumNamingStrategy.MemberName; }