Table of Contents

Class MapperBuilder<TFrom, TTo>

Namespace
LinqToDB.Tools.Mapper
Assembly
linq2db.Tools.dll

Builds a mapper that maps an object of TFrom type to an object of TTo type.

public class MapperBuilder<TFrom, TTo> : IMapperBuilder

Type Parameters

TFrom

Type to map from.

TTo

Type to map to.

Inheritance
MapperBuilder<TFrom, TTo>
Implements
Extension Methods

Properties

DeepCopy

If true, performs deep copy. if default (null), the GetMapperExpression() method does not do deep copy, however the GetMapperExpressionEx() method does.

public bool? DeepCopy { get; set; }

Property Value

bool?

FromMappingDictionary

Defines member name mapping for source types.

public Dictionary<Type, Dictionary<string, string>>? FromMappingDictionary { get; set; }

Property Value

Dictionary<Type, Dictionary<string, string>>

FromType

Type to map from.

public Type FromType { get; }

Property Value

Type

MappingSchema

Mapping schema.

public MappingSchema MappingSchema { get; set; }

Property Value

MappingSchema

MemberMappers

Member mappers.

public List<MemberMapperInfo>? MemberMappers { get; set; }

Property Value

List<MemberMapperInfo>

ProcessCrossReferences

If true, processes object cross references. if default (null), the GetMapperExpression() method does not process cross references, however the GetMapperExpressionEx() method does.

public bool? ProcessCrossReferences { get; set; }

Property Value

bool?

ToMappingDictionary

Defines member name mapping for destination types.

public Dictionary<Type, Dictionary<string, string>>? ToMappingDictionary { get; set; }

Property Value

Dictionary<Type, Dictionary<string, string>>

ToMemberFilter

Filters target members to map.

public Func<MemberAccessor, bool> ToMemberFilter { get; set; }

Property Value

Func<MemberAccessor, bool>

ToType

Type to map to.

public Type ToType { get; }

Property Value

Type

Methods

FromMapping(IReadOnlyDictionary<string, string>)

Defines member name mapping for source types.

public MapperBuilder<TFrom, TTo> FromMapping(IReadOnlyDictionary<string, string> mapping)

Parameters

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

FromMapping(string, string)

Defines member name mapping for source types.

public MapperBuilder<TFrom, TTo> FromMapping(string memberName, string mapName)

Parameters

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

FromMapping(Type, IReadOnlyDictionary<string, string>)

Defines member name mapping for source types.

public MapperBuilder<TFrom, TTo> FromMapping(Type type, IReadOnlyDictionary<string, string> mapping)

Parameters

type Type

Type to map.

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

FromMapping(Type, string, string)

Defines member name mapping for source types.

public MapperBuilder<TFrom, TTo> FromMapping(Type type, string memberName, string mapName)

Parameters

type Type

Type to map.

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

FromMapping<T>(IReadOnlyDictionary<string, string>)

Defines member name mapping for source types.

public MapperBuilder<TFrom, TTo> FromMapping<T>(IReadOnlyDictionary<string, string> mapping)

Parameters

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Type Parameters

T

Type to map.

FromMapping<T>(string, string)

Defines member name mapping for source types.

public MapperBuilder<TFrom, TTo> FromMapping<T>(string memberName, string mapName)

Parameters

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Type Parameters

T

Type to map.

GetMapper()

Returns a mapper to map an object of TFrom type to an object of TTo type.

public Mapper<TFrom, TTo> GetMapper()

Returns

Mapper<TFrom, TTo>

Mapping expression.

GetMapperExpression()

Returns a mapper expression to map an object of TFrom type to an object of TTo type. Returned expression is compatible to IQueryable.

public Expression<Func<TFrom, TTo>> GetMapperExpression()

Returns

Expression<Func<TFrom, TTo>>

Mapping expression.

GetMapperExpressionEx()

Returns a mapper expression to map an object of TFrom type to an object of TTo type.

public Expression<Func<TFrom, TTo, IDictionary<object, object>?, TTo>> GetMapperExpressionEx()

Returns

Expression<Func<TFrom, TTo, IDictionary<object, object>, TTo>>

Mapping expression.

MapMember<T>(Expression<Func<TTo, T>>, Expression<Func<TFrom, T>>)

Adds member mapper.

public MapperBuilder<TFrom, TTo> MapMember<T>(Expression<Func<TTo, T>> toMember, Expression<Func<TFrom, T>> setter)

Parameters

toMember Expression<Func<TTo, T>>

Expression that returns a member to map.

setter Expression<Func<TFrom, T>>

Expression to set the member.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Type Parameters

T

Type of the member to map.

Examples

This example shows how to explicitly convert one value to another.

Mapping(IReadOnlyDictionary<string, string>)

Defines member name mapping for source and destination types.

public MapperBuilder<TFrom, TTo> Mapping(IReadOnlyDictionary<string, string> mapping)

Parameters

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Mapping(string, string)

Defines member name mapping for source and destination types.

public MapperBuilder<TFrom, TTo> Mapping(string memberName, string mapName)

Parameters

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Mapping(Type, IReadOnlyDictionary<string, string>)

Defines member name mapping for source and destination types.

public MapperBuilder<TFrom, TTo> Mapping(Type type, IReadOnlyDictionary<string, string> mapping)

Parameters

type Type

Type to map.

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Mapping(Type, string, string)

Defines member name mapping for source and destination types.

public MapperBuilder<TFrom, TTo> Mapping(Type type, string memberName, string mapName)

Parameters

type Type

Type to map.

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Mapping<T>(IReadOnlyDictionary<string, string>)

Defines member name mapping for source and destination types.

public MapperBuilder<TFrom, TTo> Mapping<T>(IReadOnlyDictionary<string, string> mapping)

Parameters

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Type Parameters

T

Type to map.

Mapping<T>(string, string)

Defines member name mapping for source and destination types.

public MapperBuilder<TFrom, TTo> Mapping<T>(string memberName, string mapName)

Parameters

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Type Parameters

T

Type to map.

SetDeepCopy(bool?)

If true, performs deep copy.

public MapperBuilder<TFrom, TTo> SetDeepCopy(bool? deepCopy)

Parameters

deepCopy bool?

If true, performs deep copy.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

SetMappingSchema(MappingSchema)

Sets mapping schema.

public MapperBuilder<TFrom, TTo> SetMappingSchema(MappingSchema schema)

Parameters

schema MappingSchema

Mapping schema to set.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

SetProcessCrossReferences(bool?)

If true, processes object cross references.

public MapperBuilder<TFrom, TTo> SetProcessCrossReferences(bool? doProcess)

Parameters

doProcess bool?

If true, processes object cross references.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

SetToMemberFilter(Func<MemberAccessor, bool>)

Adds a predicate to filter target members to map.

public MapperBuilder<TFrom, TTo> SetToMemberFilter(Func<MemberAccessor, bool> predicate)

Parameters

predicate Func<MemberAccessor, bool>

Predicate to filter members to map.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

ToMapping(IReadOnlyDictionary<string, string>)

Defines member name mapping for destination types.

public MapperBuilder<TFrom, TTo> ToMapping(IReadOnlyDictionary<string, string> mapping)

Parameters

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

ToMapping(string, string)

Defines member name mapping for destination types.

public MapperBuilder<TFrom, TTo> ToMapping(string memberName, string mapName)

Parameters

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

ToMapping(Type, IReadOnlyDictionary<string, string>)

Defines member name mapping for destination types.

public MapperBuilder<TFrom, TTo> ToMapping(Type type, IReadOnlyDictionary<string, string> mapping)

Parameters

type Type

Type to map.

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

ToMapping(Type, string, string)

Defines member name mapping for destination types.

public MapperBuilder<TFrom, TTo> ToMapping(Type type, string memberName, string mapName)

Parameters

type Type

Type to map.

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

ToMapping<T>(IReadOnlyDictionary<string, string>)

Defines member name mapping for destination types.

public MapperBuilder<TFrom, TTo> ToMapping<T>(IReadOnlyDictionary<string, string> mapping)

Parameters

mapping IReadOnlyDictionary<string, string>

Mapping parameters.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Type Parameters

T

Type to map.

ToMapping<T>(string, string)

Defines member name mapping for destination types.

public MapperBuilder<TFrom, TTo> ToMapping<T>(string memberName, string mapName)

Parameters

memberName string

Type member name.

mapName string

Mapping name.

Returns

MapperBuilder<TFrom, TTo>

Returns this mapper.

Type Parameters

T

Type to map.