diff --git a/src/Mapster/TypeAdapterConfig.cs b/src/Mapster/TypeAdapterConfig.cs index 5c1d5908..0f5770aa 100644 --- a/src/Mapster/TypeAdapterConfig.cs +++ b/src/Mapster/TypeAdapterConfig.cs @@ -575,15 +575,35 @@ private CompileArgument GetCompileArgument(TypeTuple tuple, MapType mapType, Com }; } - public void Compile() + public void Compile(bool failFast = true) { + var exceptions = new List(); var keys = RuleMap.Keys.ToList(); + foreach (var key in keys) { - if (key.Source == typeof(void)) - continue; - _mapDict[key] = Compiler(CreateMapExpression(key, MapType.Map)); - _mapToTargetDict[key] = Compiler(CreateMapExpression(key, MapType.MapToTarget)); + try + { + if (key.Source == typeof(void)) + continue; + + _mapDict[key] = Compiler(CreateMapExpression(key, MapType.Map)); + _mapToTargetDict[key] = Compiler(CreateMapExpression(key, MapType.MapToTarget)); + } + catch (Exception ex) + { + if (failFast) + { + throw; + } + + exceptions.Add(ex); + } + } + + if (exceptions.Count > 0) + { + throw new AggregateException(exceptions); } }