This project is read-only.

Simple Mapper

Assembly  EnterpriseLibraryExtensions.dll
 Namespace  EnterpriseLibraryExtensions.Services.Mapping
 Class  SimpleMapper
 From version  1.5

The SimpleMapper class creates a simple mapping between two simple types. This can be useful when e.g. mapping enums in a DTO to enums in the business layer.

To get going, derive a new translator class from * SimpleMapper*.

public class MyMapper : SimpleMapper<DTOEnum, BusinessLayerEnum>
  public MyMapper()
    AddMapping(DTOEnum.Value, BusinessLayerEnum.Value);
    SetFallbackValue(DTOEnum.SomeValue, BusinessLayerEnum.SomeOtherValue);

What happens in the above, is a mapping between DTOEnum.Value and BusinessLayerEnum.Value is established. Additionally, a fallback value is specified with the SetFallbackValue method call. This means that if a value is not specified in the mapping, the translator will return the fallback value.

If no fallback value is provided and an unmapped value is to be translated, an InvalidOperationException will be thrown.


Register the SimpleMapper derived class on EntityTranslatorService and call Translate.

var entityTranslatorService = new EntityTranslatorService();
entityTranslatorService. RegisterEntityTranslator(new MyMapper());

BusinessLayerEnum translated = entityTranslatorService.Translate(DTOEnum.Value);

Last edited Apr 24, 2012 at 9:20 PM by RasmusTherkelsen, version 2


No comments yet.