Skip to main content

MapperAttribute

Namespace: Riok.Mapperly.Abstractions

Marks a partial class as a mapper.

public class MapperAttribute : System.Attribute

Inheritance ObjectAttributeMapperAttribute

Properties

PropertyNameMappingStrategy

Strategy on how to match mapping property names.

public PropertyNameMappingStrategy PropertyNameMappingStrategy { get; set; }

Property Value

PropertyNameMappingStrategy

EnumMappingStrategy

The default enum mapping strategy. Can be overwritten on specific enums via mapping method configurations.

public EnumMappingStrategy EnumMappingStrategy { get; set; }

Property Value

EnumMappingStrategy

EnumMappingIgnoreCase

Whether the case should be ignored for enum mappings.

public bool EnumMappingIgnoreCase { get; set; }

Property Value

Boolean

ThrowOnMappingNullMismatch

Specifies the behaviour in the case when the mapper tries to return null in a mapping method with a non-nullable return type. If set to true an ArgumentNullException is thrown. If set to false the mapper tries to return a default value. For a String this is String.Empty, for value types default and for reference types new() if a parameterless constructor exists or else an ArgumentNullException is thrown.

public bool ThrowOnMappingNullMismatch { get; set; }

Property Value

Boolean

ThrowOnPropertyMappingNullMismatch

Specifies the behaviour in the case when the mapper tries to set a non-nullable property to a null value. If set to true an ArgumentNullException is thrown. If set to false the property assignment is ignored. This is ignored for required init properties and projection mappings.

public bool ThrowOnPropertyMappingNullMismatch { get; set; }

Property Value

Boolean

AllowNullPropertyAssignment

Specifies whether null values are assigned to the target. If true (default), the source is null, and the target does allow null values, null is assigned. If false, null values are never assigned to the target property. This is ignored for required init properties and projection mappings.

public bool AllowNullPropertyAssignment { get; set; }

Property Value

Boolean

UseDeepCloning

Whether to always deep copy objects. Eg. when the type Person[] should be mapped to the same type Person[], when false, the same array is reused. when true, the array and each person is cloned.

public bool UseDeepCloning { get; set; }

Property Value

Boolean

EnabledConversions

Enabled conversions which Mapperly automatically implements. By default all supported type conversions are enabled.

Eg. to disable all automatically implemented conversions:
EnabledConversions = MappingConversionType.None

Eg. to disable ToString() method calls:
EnabledConversions = MappingConversionType.All & ~MappingConversionType.ToStringMethod

public MappingConversionType EnabledConversions { get; set; }

Property Value

MappingConversionType

UseReferenceHandling

Enables the reference handling feature. Disabled by default for performance reasons. When enabled, an IReferenceHandler instance is passed through the mapping methods to keep track of and reuse existing target object instances.

public bool UseReferenceHandling { get; set; }

Property Value

Boolean

IgnoreObsoleteMembersStrategy

The ignore obsolete attribute strategy. Determines how ObsoleteAttribute marked members are mapped. Defaults to IgnoreObsoleteMembersStrategy.None.

public IgnoreObsoleteMembersStrategy IgnoreObsoleteMembersStrategy { get; set; }

Property Value

IgnoreObsoleteMembersStrategy

RequiredMappingStrategy

Defines the strategy used when emitting warnings for unmapped members. By default this is RequiredMappingStrategy.Both, emitting warnings for unmapped source and target members.

public RequiredMappingStrategy RequiredMappingStrategy { get; set; }

Property Value

RequiredMappingStrategy

IncludedMembers

Determines the access level of members that Mapperly will map.

public MemberVisibility IncludedMembers { get; set; }

Property Value

MemberVisibility

PreferParameterlessConstructors

Controls the priority of constructors used in mapping. When true, a parameterless constructor is prioritized over constructors with parameters. When false, accessible constructors are ordered in descending order by their parameter count.

public bool PreferParameterlessConstructors { get; set; }

Property Value

Boolean

AutoUserMappings

Whether to automatically discover user mapping methods based on their signature. Partial methods are always considered mapping methods. If true, all partial methods and methods with an implementation body and a mapping method signature are discovered as mapping methods. If false only partial methods and methods with a UserMappingAttribute are discovered.

To discover mappings in external mappers (UseMapperAttribute and UseStaticMapperAttribute) the same rules are applied: If set to true all methods with a mapping method signature are automatically discovered. If set to false methods with a UserMappingAttribute and if the containing class has a MapperAttribute partial methods are discovered.

public bool AutoUserMappings { get; set; }

Property Value

Boolean

TypeId

public object TypeId { get; }

Property Value

Object

Constructors

MapperAttribute()

public MapperAttribute()