@@ -13,7 +13,7 @@ public void AssertConfigurationExpressionIsValid(TypeMap[] typeMaps)
1313 . Select ( g => ( TypePair : g . Key , ProfileNames : g . Select ( tmc => tmc . profile . ProfileName ) . ToArray ( ) ) )
1414 . Select ( g => new DuplicateTypeMapConfigurationException . TypeMapConfigErrors ( g . TypePair , g . ProfileNames ) )
1515 . ToArray ( ) ;
16- if ( duplicateTypeMapConfigs . Length != 0 )
16+ if ( duplicateTypeMapConfigs . Length != 0 )
1717 {
1818 throw new DuplicateTypeMapConfigurationException ( duplicateTypeMapConfigs ) ;
1919 }
@@ -29,49 +29,49 @@ where typeMap.ShouldCheckForValid
2929 let canConstruct = typeMap . PassesCtorValidation
3030 where unmappedPropertyNames . Length > 0 || ! canConstruct
3131 select new AutoMapperConfigurationException . TypeMapConfigErrors ( typeMap , unmappedPropertyNames , canConstruct ) ) . ToArray ( ) ;
32- if ( badTypeMaps . Length > 0 )
32+ if ( badTypeMaps . Length > 0 )
3333 {
3434 configExceptions . Add ( new AutoMapperConfigurationException ( badTypeMaps ) ) ;
3535 }
3636 HashSet < TypeMap > typeMapsChecked = [ ] ;
37- foreach ( var typeMap in typeMaps )
37+ foreach ( var typeMap in typeMaps )
3838 {
3939 DryRunTypeMap ( typeMap . Types , typeMap , null ) ;
4040 }
41- if ( configExceptions . Count > 1 )
41+ if ( configExceptions . Count > 1 )
4242 {
4343 throw new AggregateException ( configExceptions ) ;
4444 }
45- if ( configExceptions . Count > 0 )
45+ if ( configExceptions . Count > 0 )
4646 {
4747 throw configExceptions [ 0 ] ;
4848 }
4949 void DryRunTypeMap ( TypePair types , TypeMap typeMap , MemberMap memberMap )
5050 {
51- if ( typeMap == null )
51+ if ( typeMap == null )
5252 {
53- if ( types . ContainsGenericParameters )
53+ if ( types . ContainsGenericParameters )
5454 {
5555 return ;
5656 }
5757 typeMap = config . ResolveTypeMap ( types . SourceType , types . DestinationType ) ;
5858 }
59- if ( typeMap != null )
59+ if ( typeMap != null )
6060 {
61- if ( typeMapsChecked . Add ( typeMap ) && Validate ( new ( types , memberMap , configExceptions , typeMap ) ) && typeMap . ShouldCheckForValid )
61+ if ( typeMapsChecked . Add ( typeMap ) && Validate ( new ( types , memberMap , configExceptions , typeMap ) ) && typeMap . ShouldCheckForValid )
6262 {
6363 CheckPropertyMaps ( typeMap ) ;
6464 }
6565 }
6666 else
6767 {
6868 var mapperToUse = config . FindMapper ( types ) ;
69- if ( mapperToUse == null )
69+ if ( mapperToUse == null )
7070 {
7171 configExceptions . Add ( new AutoMapperConfigurationException ( memberMap . TypeMap . Types ) { MemberMap = memberMap } ) ;
7272 return ;
7373 }
74- if ( Validate ( new ( types , memberMap , configExceptions , ObjectMapper : mapperToUse ) ) && mapperToUse . GetAssociatedTypes ( types ) is TypePair newTypes &&
74+ if ( Validate ( new ( types , memberMap , configExceptions , ObjectMapper : mapperToUse ) ) && mapperToUse . GetAssociatedTypes ( types ) is TypePair newTypes &&
7575 newTypes != types )
7676 {
7777 DryRunTypeMap ( newTypes , null , memberMap ) ;
@@ -80,15 +80,15 @@ void DryRunTypeMap(TypePair types, TypeMap typeMap, MemberMap memberMap)
8080 }
8181 void CheckPropertyMaps ( TypeMap typeMap )
8282 {
83- foreach ( var memberMap in typeMap . MemberMaps )
83+ foreach ( var memberMap in typeMap . MemberMaps )
8484 {
85- if ( memberMap . Ignored || ( memberMap is PropertyMap && typeMap . ConstructorParameterMatches ( memberMap . DestinationName ) ) )
85+ if ( memberMap . Ignored || ( memberMap is PropertyMap && typeMap . ConstructorParameterMatches ( memberMap . DestinationName ) ) )
8686 {
8787 continue ;
8888 }
8989 var sourceType = memberMap . SourceType ;
9090 // when we don't know what the source type is, bail
91- if ( sourceType . IsGenericParameter || sourceType == typeof ( object ) )
91+ if ( sourceType . IsGenericParameter || sourceType == typeof ( object ) )
9292 {
9393 continue ;
9494 }
@@ -97,17 +97,14 @@ void CheckPropertyMaps(TypeMap typeMap)
9797 }
9898 bool Validate ( ValidationContext context )
9999 {
100- foreach ( var validator in Expression . Validators )
100+ try
101101 {
102- try
103- {
104- validator ( context ) ;
105- }
106- catch ( Exception e )
107- {
108- configExceptions . Add ( e ) ;
109- return false ;
110- }
102+ Expression . Validators ? . Invoke ( context ) ;
103+ }
104+ catch ( Exception e )
105+ {
106+ configExceptions . Add ( e ) ;
107+ return false ;
111108 }
112109 return true ;
113110 }
0 commit comments