Show / Hide Table of Contents

Class SoMapper

Class for mapping values between class-instances and types based on similarly named properties with fundamentally compatible types.

basic principle of operation is adhering to the "Duck test": "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

Inheritance
object
SoMapper
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public class SoMapper

Constructors

SoMapper()

Default constructor

Declaration
public SoMapper()

Properties

Instance

The default-instance of SoMapper for usage in cases where customization is not needed.

Declaration
public static SoMapper Instance { get; }
Property Value
Type Description
SoMapper

Methods

Clone<TInput>(TInput)

Clones the given object-graph using a recursive copy of public properties. If class being copied depends on private fields, the copy may not function as expected.

Declaration
public TInput Clone<TInput>(TInput source) where TInput : new()
Parameters
Type Name Description
TInput source

Instance to clone.

Returns
Type Description
TInput

The converted value.

Type Parameters
Name Description
TInput

Type of input-value.

CopyProperties(Type, Type, object, object, bool, bool, bool)

Copies all properties of the provided source-instance onto the provided destination-instance.

Declaration
public void CopyProperties(Type sourceType, Type destinationType, object source, object destination, bool throwOnMismatch, bool copyNulls = false, bool caseInsensitive = false)
Parameters
Type Name Description
Type sourceType

Type of the source value.

Type destinationType

Type of the destination value.

object source

Source-value to copy.

object destination

Target-value which properties will be copied onto.

bool throwOnMismatch

If true, throws when there is a mismatch between the types being converted. If false, silently ignores property with mismatch and moves along to the next one.

bool copyNulls

Should null values on source be skipped and left unchanged on dest, or copied to destionation?

bool caseInsensitive

Exact match of parameter names or case insensitivity?

CopyProperties<TSource, TDestination>(TSource, TDestination, bool, bool, bool)

Copies all properties of the provided source-instance onto the provided destination-instance.

Declaration
public void CopyProperties<TSource, TDestination>(TSource source, TDestination destination, bool throwOnMismatch, bool copyNulls = false, bool caseInsensitive = false)
Parameters
Type Name Description
TSource source

Source-value to copy.

TDestination destination

Target-value which properties will be copied onto.

bool throwOnMismatch

If true, throws when there is a mismatch between the types being converted. If false, silently ignores property with mismatch and moves along to the next one.

bool copyNulls

Should null values on source be skipped and left unchanged on dest, or copied to destionation?

bool caseInsensitive

Exact match of parameter names or case insensitivity?

Type Parameters
Name Description
TSource

Type of the source value.

TDestination

Type of the destination value.

CopyProperties<TSource, TDestination>(TSource[], TDestination[], bool, bool, bool)

Class for mapping values between class-instances and types based on similarly named properties with fundamentally compatible types.

basic principle of operation is adhering to the "Duck test": "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

Declaration
public void CopyProperties<TSource, TDestination>(TSource[] source, TDestination[] destination, bool throwOnMismatch, bool copyNulls = false, bool caseInsensitive = false) where TDestination : new()
Parameters
Type Name Description
TSource[] source
TDestination[] destination
bool throwOnMismatch
bool copyNulls
bool caseInsensitive
Type Parameters
Name Description
TSource
TDestination

GetDictionaryKey(object)

Class for mapping values between class-instances and types based on similarly named properties with fundamentally compatible types.

basic principle of operation is adhering to the "Duck test": "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

Declaration
protected object GetDictionaryKey(object dictionaryEnumerationItem)
Parameters
Type Name Description
object dictionaryEnumerationItem
Returns
Type Description
object

GetDictionaryValue(object)

Class for mapping values between class-instances and types based on similarly named properties with fundamentally compatible types.

basic principle of operation is adhering to the "Duck test": "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

Declaration
protected object GetDictionaryValue(object dictionaryEnumerationItem)
Parameters
Type Name Description
object dictionaryEnumerationItem
Returns
Type Description
object

MapValue(Type, Type, object, bool)

Class for mapping values between class-instances and types based on similarly named properties with fundamentally compatible types.

basic principle of operation is adhering to the "Duck test": "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."

Declaration
public object MapValue(Type type1, Type type2, object sourceValue, bool throwOnMismatch = true)
Parameters
Type Name Description
Type type1
Type type2
object sourceValue
bool throwOnMismatch
Returns
Type Description
object

Map<TInput, TResult>(TInput, bool)

Convert the given input instance and return a instance of the specified output type using fuzzy Duck-typing and logic. Will return same instance if the provided types are the same.

Declaration
public TResult Map<TInput, TResult>(TInput source, bool throwOnMismatch = true) where TResult : new()
Parameters
Type Name Description
TInput source

Value to convert.

bool throwOnMismatch

If true, throws when there is a mismatch between the types being converted. If false, silently ignores property with mismatch and moves along to the next one.

Returns
Type Description
TResult

The converted value.

Type Parameters
Name Description
TInput

Type of input-value.

TResult

Type of desired return-value.

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
ObjectExtensions.AssignByReflection<T>(T, T)
ObjectExtensions.GraphCopy<T>(T)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top