Table of Contents

Class ForgePropertyAttribute

Namespace
ForgeMap
Assembly
ForgeMap.Abstractions.dll

Maps a source property to a differently-named destination property.

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
public sealed class ForgePropertyAttribute : Attribute
Inheritance
object
Attribute
ForgePropertyAttribute

Constructors

ForgePropertyAttribute(string, string)

Creates a new ForgePropertyAttribute.

public ForgePropertyAttribute(string sourceProperty, string destinationProperty)

Parameters

sourceProperty string

The name of the source property (can use dot notation for nested paths).

destinationProperty string

The name of the destination property.

Properties

CollectionUpdate

Specifies how a collection property is updated when ExistingTarget is true. Ignored when ExistingTarget is false or the property is not a collection type. Default is Replace.

public CollectionUpdateStrategy CollectionUpdate { get; set; }

Property Value

CollectionUpdateStrategy

Condition

Name of a predicate method on the forger class. Called with the source property value; when it returns false, the destination assignment is skipped. Signature: bool MethodName(TSourceProperty value). Static or instance, any accessibility. Mutually exclusive with SkipWhen on the same [ForgeProperty]. Cannot be combined with [ForgeFrom] or [ForgeWith] on the same destination property. Not supported on properties bound to a constructor parameter, an init setter, or a required member.

public string? Condition { get; set; }

Property Value

string

ConvertWith

Specifies a static or instance method on the forger class to use for converting this individual property's value. The method must accept the source property type and return the destination property type (e.g., TDest MethodName(TSource value)). When set, this takes precedence over default assignment for this property only.

public string? ConvertWith { get; set; }

Property Value

string

ConvertWithType

Specifies a type that implements ITypeConverter<TSource, TDestination> to use for converting this individual property's value. The type must have an accessible parameterless constructor. When set, this takes precedence over default assignment for this property only. Cannot be combined with ConvertWith (method name).

public Type? ConvertWithType { get; set; }

Property Value

Type

DestinationProperty

Gets the name of the destination property.

public string DestinationProperty { get; }

Property Value

string

ExistingTarget

When true, the destination property's existing value is updated in place rather than replaced with a new instance. Requires the destination property to be a readable reference-type property. Runtime null values on the destination are handled according to the configured NullPropertyHandling (skip/coalesce/throw). Used with UseExistingValueAttribute mutation methods to preserve object identity (e.g., EF Core change tracking). Default is false.

public bool ExistingTarget { get; set; }

Property Value

bool

KeyProperty

The property name used as a matching key for Sync. Both source and destination element types must have a property with this name. Required when CollectionUpdate is Sync.

public string? KeyProperty { get; set; }

Property Value

string

NullPropertyHandling

Gets or sets how a nullable source property should be assigned to a non-nullable destination property. Overrides the forger-level and assembly-level NullPropertyHandling for this property. A value of (NullPropertyHandling)(-1) means "not set" (inherit from forger/assembly).

public NullPropertyHandling NullPropertyHandling { get; set; }

Property Value

NullPropertyHandling

SelectProperty

Name of a property on the source collection's element type to project. When set, generates a LINQ Select over the source collection that reads the named member, then materializes the result into the destination wrapper: List<T>/IList<T>/ICollection<T>/IReadOnlyList<T>/IReadOnlyCollection<T> via ToList(); arrays via ToArray(); HashSet<T> via the set constructor; ReadOnlyCollection<T> by wrapping a list; or returned as IEnumerable<T> directly. Built-in element coercions (enum cast, string↔enum, enum→string, DateTimeOffsetDateTime, Nullable<T> unwrap) are composed into the lambda. Use nameof() for compile-time safety. Mutually exclusive with ConvertWith, ConvertWithType, [ForgeFrom], and [ForgeWith] on the same destination property.

public string? SelectProperty { get; set; }

Property Value

string

SkipWhen

Name of a predicate method on the forger class. Called with the source object; when it returns true, the destination assignment is skipped. Signature: bool MethodName(TSource source). Static or instance, any accessibility. Mutually exclusive with Condition on the same [ForgeProperty]. Cannot be combined with [ForgeFrom] or [ForgeWith] on the same destination property. Not supported on properties bound to a constructor parameter, an init setter, or a required member.

public string? SkipWhen { get; set; }

Property Value

string

SourceProperty

Gets the name of the source property.

public string SourceProperty { get; }

Property Value

string