1
在Automapper中有例外的two types,我無法在任何地方找到關於如何使用它們的信息。如何處理Automapper異常(try/catch)
唯一的例外是 AutoMapperMappingException 和 AutoMapperConfigurationException
有誰知道這兩個的區別和我應該怎麼設置的try/catch又在哪裏?
在Automapper中有例外的two types,我無法在任何地方找到關於如何使用它們的信息。如何處理Automapper異常(try/catch)
唯一的例外是 AutoMapperMappingException 和 AutoMapperConfigurationException
有誰知道這兩個的區別和我應該怎麼設置的try/catch又在哪裏?
檢查source code。
AutoMapperConfigurationException在映射配置文件由AutoMapper加載時使用。它在執行配置檢查時拋出了我的Automapper。
[Test]
public void Mapper_AssertConfigurationIsValid_Expect_No_Exceptions()
{
AutoMapper.Mapper.AssertConfigurationIsValid();
}
AutoMapperMappingException「運行」過程中使用......當實際映射代碼運行時把你的源DTO到目的地DTO是。
HTH。
所以你永遠不會使用AssertConfigurationIsValid除了在unittests?所以在我的代碼中,我總是會嘗試/捕獲AutoMapperMappingException,並且基本上會捕獲相同的東西? – Sturla
這就對了 - AssertConfigurationIsValid只在測試中。此外,我從來沒有捕捉到「AutoMapperMappingException」 - 它不是我們所期望的或我們知道如何處理的。你的情況可能會有所不同。 – ozczecho