Class UmbracoMapper
Umbraco Mapper.
Inheritance
Namespace: Umbraco.Core.Mapping
Assembly: Umbraco.Core.dll
Syntax
public class UmbracoMapper
Remarks
When a map is defined from TSource to TTarget, the mapper automatically knows how to map from IEnumerable{TSource} to IEnumerable{TTarget} (using a List{TTarget}) and to TTarget[].
When a map is defined from TSource to TTarget, the mapper automatically uses that map for any source type that inherits from, or implements, TSource.
When a map is defined from TSource to TTarget, the mapper can map to TTarget exclusively and cannot re-use that map for types that would inherit from, or implement, TTarget.
When using the Map{TSource, TTarget}(TSource source, ...) overloads, TSource is explicit. When using the Map{TTarget}(object source, ...) TSource is defined as source.GetType().
In both cases, TTarget is explicit and not typeof(target).
Constructors
View SourceUmbracoMapper(MapDefinitionCollection)
Initializes a new instance of the UmbracoMapper class.
Declaration
[Obsolete("This constructor is no longer used and will be removed in future versions, use the other constructor instead")]
public UmbracoMapper(MapDefinitionCollection profiles)
Parameters
Type | Name | Description |
---|---|---|
MapDefinitionCollection | profiles |
UmbracoMapper(MapDefinitionCollection, IScopeProvider)
Initializes a new instance of the UmbracoMapper class.
Declaration
public UmbracoMapper(MapDefinitionCollection profiles, IScopeProvider scopeProvider)
Parameters
Type | Name | Description |
---|---|---|
MapDefinitionCollection | profiles | |
IScopeProvider | scopeProvider |
Methods
View SourceDefine<TSource, TTarget>()
Defines a mapping.
Declaration
public void Define<TSource, TTarget>()
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Define<TSource, TTarget>(Action<TSource, TTarget, MapperContext>)
Defines a mapping.
Declaration
public void Define<TSource, TTarget>(Action<TSource, TTarget, MapperContext> map)
Parameters
Type | Name | Description |
---|---|---|
System.Action<TSource, TTarget, MapperContext> | map | A mapping method. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Define<TSource, TTarget>(Func<TSource, MapperContext, TTarget>)
Defines a mapping.
Declaration
public void Define<TSource, TTarget>(Func<TSource, MapperContext, TTarget> ctor)
Parameters
Type | Name | Description |
---|---|---|
System.Func<TSource, MapperContext, TTarget> | ctor | A constructor method. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Define<TSource, TTarget>(Func<TSource, MapperContext, TTarget>, Action<TSource, TTarget, MapperContext>)
Defines a mapping.
Declaration
public void Define<TSource, TTarget>(Func<TSource, MapperContext, TTarget> ctor, Action<TSource, TTarget, MapperContext> map)
Parameters
Type | Name | Description |
---|---|---|
System.Func<TSource, MapperContext, TTarget> | ctor | A constructor method. |
System.Action<TSource, TTarget, MapperContext> | map | A mapping method. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Map<TTarget>(Object)
Maps a source object to a new target object.
Declaration
public TTarget Map<TTarget>(object source)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TTarget | The target type. |
Map<TTarget>(Object, Action<MapperContext>)
Maps a source object to a new target object.
Declaration
public TTarget Map<TTarget>(object source, Action<MapperContext> f)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object. |
System.Action<MapperContext> | f | A mapper context preparation method. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TTarget | The target type. |
Map<TTarget>(Object, MapperContext)
Maps a source object to a new target object.
Declaration
public TTarget Map<TTarget>(object source, MapperContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Object | source | The source object. |
MapperContext | context | A mapper context. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TTarget | The target type. |
Map<TSource, TTarget>(TSource)
Maps a source object to a new target object.
Declaration
public TTarget Map<TSource, TTarget>(TSource source)
Parameters
Type | Name | Description |
---|---|---|
TSource | source | The source object. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Map<TSource, TTarget>(TSource, TTarget)
Maps a source object to an existing target object.
Declaration
public TTarget Map<TSource, TTarget>(TSource source, TTarget target)
Parameters
Type | Name | Description |
---|---|---|
TSource | source | The source object. |
TTarget | target | The target object. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Map<TSource, TTarget>(TSource, TTarget, Action<MapperContext>)
Maps a source object to an existing target object.
Declaration
public TTarget Map<TSource, TTarget>(TSource source, TTarget target, Action<MapperContext> f)
Parameters
Type | Name | Description |
---|---|---|
TSource | source | The source object. |
TTarget | target | The target object. |
System.Action<MapperContext> | f | A mapper context preparation method. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Map<TSource, TTarget>(TSource, TTarget, MapperContext)
Maps a source object to an existing target object.
Declaration
public TTarget Map<TSource, TTarget>(TSource source, TTarget target, MapperContext context)
Parameters
Type | Name | Description |
---|---|---|
TSource | source | The source object. |
TTarget | target | The target object. |
MapperContext | context | A mapper context. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Map<TSource, TTarget>(TSource, Action<MapperContext>)
Maps a source object to a new target object.
Declaration
public TTarget Map<TSource, TTarget>(TSource source, Action<MapperContext> f)
Parameters
Type | Name | Description |
---|---|---|
TSource | source | The source object. |
System.Action<MapperContext> | f | A mapper context preparation method. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
Map<TSource, TTarget>(TSource, MapperContext)
Maps a source object to a new target object.
Declaration
public TTarget Map<TSource, TTarget>(TSource source, MapperContext context)
Parameters
Type | Name | Description |
---|---|---|
TSource | source | The source object. |
MapperContext | context | A mapper context. |
Returns
Type | Description |
---|---|
TTarget | The target object. |
Type Parameters
Name | Description |
---|---|
TSource | The source type. |
TTarget | The target type. |
MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement>)
Maps an enumerable of source objects to a new list of target objects.
Declaration
public List<TTargetElement> MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement> source)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TSourceElement> | source | The source objects. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<TTargetElement> | A list containing the target objects. |
Type Parameters
Name | Description |
---|---|
TSourceElement | The type of the source objects. |
TTargetElement | The type of the target objects. |
MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement>, Action<MapperContext>)
Maps an enumerable of source objects to a new list of target objects.
Declaration
public List<TTargetElement> MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement> source, Action<MapperContext> f)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TSourceElement> | source | The source objects. |
System.Action<MapperContext> | f | A mapper context preparation method. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<TTargetElement> | A list containing the target objects. |
Type Parameters
Name | Description |
---|---|
TSourceElement | The type of the source objects. |
TTargetElement | The type of the target objects. |
MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement>, MapperContext)
Maps an enumerable of source objects to a new list of target objects.
Declaration
public List<TTargetElement> MapEnumerable<TSourceElement, TTargetElement>(IEnumerable<TSourceElement> source, MapperContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<TSourceElement> | source | The source objects. |
MapperContext | context | A mapper context. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<TTargetElement> | A list containing the target objects. |
Type Parameters
Name | Description |
---|---|
TSourceElement | The type of the source objects. |
TTargetElement | The type of the target objects. |