Show / Hide Table of Contents

Class Mapper

Provides mapping functionality to map properties of one type to another. Properties of the same name are automatically mapped. Name mapping is case insensitive.

Inheritance
System.Object
Mapper
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Sartorius.SAF.Mapping
Assembly: Sartorius.SAF.dll
Syntax
public static class Mapper
Remarks

The Mapper class provides easier configuration than AutoMapper and is faster. In most cases the Mapper can be used with zero configuration. Configuration of the Mapper can be done several times at different points, whereas AutoMapper can only be configured once per System.AppDomain.

Examples

The following example shows how to use the Mapper without any configuration to map the properties from one object to another existing object.

            Mapper.Map(entity, obj);

The following example shows how to use the Mapper to create a new object mapped from another object.

            var obj = Mapper.Map<TransferObject>(entity);

The following example shows how to configure mapping when objects do not share the same property names or need some kind of conversion.

            Mapper.AddMapping<Entity, DifferentNamingTransferObject>((e, o) =>
        {
            o.Alpha = e.A;
            o.Beta = e.B;
        });

        Mapper.Map(entity, obj);

Methods

View Source

AddMapping<TSource, TTarget>(Action<TSource, TTarget>)

Adds a mapping action that is called when mapping an item of type TSource to a type of TTarget.

Declaration
public static void AddMapping<TSource, TTarget>(Action<TSource, TTarget> mappingAction)
Parameters
Type Name Description
System.Action<TSource, TTarget> mappingAction

The mapping action.

Type Parameters
Name Description
TSource

Type of the source.

TTarget

Type of the target.

View Source

Map<TTarget>(IEnumerable<Object>)

Creates instances of the target type and maps the properties of the source items to these instances.

Declaration
public static IEnumerable<TTarget> Map<TTarget>(IEnumerable<object> source)
    where TTarget : new()
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Object> source

The source item.

Returns
Type Description
System.Collections.Generic.IEnumerable<TTarget>

An enumerable of target items being mapped from the source items.

Type Parameters
Name Description
TTarget

Type of the target.

Remarks

Properties having the same name and same property type are mapped to each other when the source property is readable and the target property is writable.

View Source

Map<TTarget>(Object)

Maps the properties of the source item to a target item.

Declaration
public static TTarget Map<TTarget>(object source)
    where TTarget : new()
Parameters
Type Name Description
System.Object source

The source item.

Returns
Type Description
TTarget

A TTarget.

Type Parameters
Name Description
TTarget

Type of the target.

Remarks

Properties having the same name and same property type are mapped to each other when the source property is readable and the target property is writable.

View Source

Map<TSource, TTarget>(TSource)

Created a new instance of the target type and maps the properties of the source item to this new instance.

Declaration
public static TTarget Map<TSource, TTarget>(TSource source)
    where TTarget : new()
Parameters
Type Name Description
TSource source

The source item.

Returns
Type Description
TTarget

A TTarget.

Type Parameters
Name Description
TSource

Type of the source.

TTarget

Type of the target.

Remarks

Properties having the same name and same property type are mapped to each other when the source property is readable and the target property is writable.

View Source

Map<TSource, TTarget>(TSource, TTarget)

Maps the properties of the source item to a target item.

Declaration
public static void Map<TSource, TTarget>(TSource source, TTarget target)
Parameters
Type Name Description
TSource source

The source item.

TTarget target

The target item.

Type Parameters
Name Description
TSource

Type of the source.

TTarget

Type of the target.

Remarks

Properties having the same name and same property type are mapped to each other when the source property is readable and the target property is writable.

View Source

Map<TSource, TTarget>(IEnumerable<TSource>)

Creates instances of the target type and maps the properties of the source items to these instances.

Declaration
public static IEnumerable<TTarget> Map<TSource, TTarget>(IEnumerable<TSource> source)
    where TTarget : new()
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<TSource> source

The source item.

Returns
Type Description
System.Collections.Generic.IEnumerable<TTarget>

An enumerable of target items being mapped from the source items.

Type Parameters
Name Description
TSource

Type of the source.

TTarget

Type of the target.

Remarks

Properties having the same name and same property type are mapped to each other when the source property is readable and the target property is writable.

  • View Source
Back to top Generated by DocFX