如何处理Automapper异常(try / catch)

时间:2014-02-24 11:21:04

标签: c# automapper

Automapper中存在 two types 异常,我无法在任何地方找到有关如何使用它们的信息。

例外情况是     的 AutoMapperMappingException 和     的 AutoMapperConfigurationException

有没有人知道这两者的区别以及我应该如何为它们设置try / catch?

1 个答案:

答案 0 :(得分:2)

检查source code

AutoMapper加载映射配置文件时使用

AutoMapperConfigurationException 。它在执行配置检查时抛出了我的Automapper。

    [Test]
    public void Mapper_AssertConfigurationIsValid_Expect_No_Exceptions()
    {
        AutoMapper.Mapper.AssertConfigurationIsValid();
    }

AutoMapperMappingException 用于"运行时" ...即运行实际的映射代码以将源dto转到目的地dto。

HTH。

相关问题