Skip to main content

IReferenceHandler

Namespace: Riok.Mapperly.Abstractions.ReferenceHandling

A reference handler can store and resolve references of mapping target objects.

public interface IReferenceHandler

Methods

TryGetReference<TSource, TTarget>(TSource, TTarget&)

Before an object is created by Mapperly this method is called. It can attempt to resolve existing target object instances based on the source object instance. If false is returned, Mapperly creates a new instance of the target class. If true is returned, target has to be non-null. Mapperly then uses the target instance.

bool TryGetReference<TSource, TTarget>(TSource source, TTarget& target)

Type Parameters

TSource
The type of the source object.

TTarget
The target object type.

Parameters

source TSource
The source object instance.

target TTarget&
The resolved target object instance or null if none could be resolved.

Returns

Boolean

SetReference<TSource, TTarget>(TSource, TTarget)

Stores the created target instance. Called by Mapperly just after a new target object instance is created.

void SetReference<TSource, TTarget>(TSource source, TTarget target)

Type Parameters

TSource
The type of the source object.

TTarget
The type of the target object.

Parameters

source TSource
The source object instance.

target TTarget
The target object instance.