Skip to content

Commit 87a9e35

Browse files
committed
no need to throw to report errors
1 parent 956975b commit 87a9e35

File tree

5 files changed

+106
-111
lines changed

5 files changed

+106
-111
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ dotnet_style_namespace_match_folder = true:silent
8686
dotnet_style_explicit_tuple_names = true:suggestion
8787
dotnet_style_prefer_inferred_tuple_names = true:suggestion
8888
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
89+
csharp_style_prefer_primary_constructors = true:suggestion
90+
csharp_prefer_system_threading_lock = true:suggestion
91+
csharp_space_after_keywords_in_control_flow_statements = true
8992

9093
[*.xml]
9194
indent_size = 2

docs/source/Configuration-validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ To skip validation altogether for this map, use `MemberList.None`. That's the de
5555

5656
## Custom validations
5757

58-
You can add custom validations through an extension point. See [here](https://github.com/AutoMapper/AutoMapper/blob/bdc0120497d192a2741183415543f6119f50a982/src/UnitTests/CustomValidations.cs#L42).
58+
You can add custom validations through an extension point. See [here](https://github.com/AutoMapper/AutoMapper/blob/master/src/UnitTests/CustomValidations.cs).

src/AutoMapper/Configuration/ConfigurationValidator.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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,13 +97,13 @@ void CheckPropertyMaps(TypeMap typeMap)
9797
}
9898
bool Validate(ValidationContext context)
9999
{
100-
foreach(var validator in Expression.Validators)
100+
foreach (var validator in Expression.Validators)
101101
{
102102
try
103103
{
104104
validator(context);
105105
}
106-
catch(Exception e)
106+
catch (Exception e)
107107
{
108108
configExceptions.Add(e);
109109
return false;

0 commit comments

Comments
 (0)