Skip to content
Merged
Prev Previous commit
Next Next commit
Rename ShouldMapConstructor to ShouldUseConstructor
  • Loading branch information
lxalln committed Jun 24, 2018
commit f463a47b40f4d55085084b3576c8f2b7d6f1e82a
2 changes: 1 addition & 1 deletion src/AutoMapper/Configuration/IProfileConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface IProfileConfiguration
/// Specify which constructors should be mapped.
/// By default all non-static constructors are mapped.
/// </summary>
Func<ConstructorInfo, bool> ShouldMapConstructor { get; }
Func<ConstructorInfo, bool> ShouldUseConstructor { get; }

string ProfileName { get; }
IEnumerable<string> GlobalIgnores { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/IProfileExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public interface IProfileExpression

Func<PropertyInfo, bool> ShouldMapProperty { get; set; }
Func<FieldInfo, bool> ShouldMapField { get; set; }
Func<ConstructorInfo, bool> ShouldMapConstructor { get; set; }
Func<ConstructorInfo, bool> ShouldUseConstructor { get; set; }

string ProfileName { get; }
IMemberConfiguration AddMemberConfiguration();
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ IEnumerable<Action<PropertyMap, IMemberConfigurationExpression>> IProfileConfigu
public bool? EnableNullPropagationForQueryMapping { get; set; }
public Func<PropertyInfo, bool> ShouldMapProperty { get; set; }
public Func<FieldInfo, bool> ShouldMapField { get; set; }
public Func<ConstructorInfo, bool> ShouldMapConstructor { get; set; }
public Func<ConstructorInfo, bool> ShouldUseConstructor { get; set; }

public INamingConvention SourceMemberNamingConvention { get; set; }
public INamingConvention DestinationMemberNamingConvention { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/AutoMapper/ProfileMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ProfileMap(IProfileConfiguration profile, IConfiguration configuration)
ConstructorMappingEnabled = profile.ConstructorMappingEnabled ?? configuration?.ConstructorMappingEnabled ?? true;
ShouldMapField = profile.ShouldMapField ?? configuration?.ShouldMapField ?? (p => p.IsPublic());
ShouldMapProperty = profile.ShouldMapProperty ?? configuration?.ShouldMapProperty ?? (p => p.IsPublic());
ShouldMapConstructor = profile.ShouldMapConstructor ?? configuration?.ShouldMapConstructor ?? (c => true);
ShouldUseConstructor = profile.ShouldUseConstructor ?? configuration?.ShouldUseConstructor ?? (c => true);
CreateMissingTypeMaps = profile.CreateMissingTypeMaps ?? configuration?.CreateMissingTypeMaps ?? true;
ValidateInlineMaps = profile.ValidateInlineMaps ?? configuration?.ValidateInlineMaps ?? true;

Expand Down Expand Up @@ -84,7 +84,7 @@ public ProfileMap(IProfileConfiguration profile, IConfiguration configuration)
public string Name { get; }
public Func<FieldInfo, bool> ShouldMapField { get; }
public Func<PropertyInfo, bool> ShouldMapProperty { get; }
public Func<ConstructorInfo, bool> ShouldMapConstructor { get; }
public Func<ConstructorInfo, bool> ShouldUseConstructor { get; }

public IEnumerable<Action<PropertyMap, IMemberConfigurationExpression>> AllPropertyMapActions { get; }
public IEnumerable<Action<TypeMap, IMappingExpression>> AllTypeMapActions { get; }
Expand Down
6 changes: 3 additions & 3 deletions src/AutoMapper/TypeDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TypeDetails(Type type, ProfileMap config)
PublicReadAccessors = BuildPublicReadAccessors(publicReadableMembers);
PublicWriteAccessors = BuildPublicAccessors(publicWritableMembers);
PublicNoArgMethods = BuildPublicNoArgMethods();
Constructors = GetAllConstructors(config.ShouldMapConstructor);
Constructors = GetAllConstructors(config.ShouldUseConstructor);
PublicNoArgExtensionMethods = BuildPublicNoArgExtensionMethods(config.SourceExtensionMethods);
AllMembers = PublicReadAccessors.Concat(PublicNoArgMethods).Concat(PublicNoArgExtensionMethods).ToList();
DestinationMemberNames = AllMembers.Select(mi => new DestinationMemberName { Member = mi, Possibles = PossibleNames(mi.Name, config.Prefixes, config.Postfixes).ToArray() });
Expand Down Expand Up @@ -166,9 +166,9 @@ private IEnumerable<MemberInfo> GetAllPublicReadableMembers(Func<MemberInfo, boo
private IEnumerable<MemberInfo> GetAllPublicWritableMembers(Func<MemberInfo, bool> membersToMap)
=> GetAllPublicMembers(PropertyWritable, FieldWritable, membersToMap);

private IEnumerable<ConstructorInfo> GetAllConstructors(Func<ConstructorInfo, bool> shouldMapConstructor)
private IEnumerable<ConstructorInfo> GetAllConstructors(Func<ConstructorInfo, bool> shouldUseConstructor)
{
return Type.GetDeclaredConstructors().Where(shouldMapConstructor).ToArray();
return Type.GetDeclaredConstructors().Where(shouldUseConstructor).ToArray();
}

private static bool PropertyReadable(PropertyInfo propertyInfo) => propertyInfo.CanRead;
Expand Down
14 changes: 7 additions & 7 deletions src/UnitTests/ShouldMapConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AutoMapper.UnitTests
{
public class ShouldMapConstructorInternal : NonValidatingSpecBase
public class ShouldUseConstructorInternal : NonValidatingSpecBase
{
class Destination
{
Expand Down Expand Up @@ -34,7 +34,7 @@ class Source
protected override MapperConfiguration Configuration { get; } = new MapperConfiguration(
cfg =>
{
cfg.ShouldMapConstructor = c => c.IsAssembly;
cfg.ShouldUseConstructor = c => c.IsAssembly;
cfg.CreateMap<Source, Destination>();
});

Expand All @@ -46,7 +46,7 @@ public void Should_only_map_internal_ctor()
}
}

public class ShouldMapConstructorPrivate : NonValidatingSpecBase
public class ShouldUseConstructorPrivate : NonValidatingSpecBase
{

class Destination
Expand Down Expand Up @@ -77,7 +77,7 @@ class Source
protected override MapperConfiguration Configuration { get; } = new MapperConfiguration(
cfg =>
{
cfg.ShouldMapConstructor = c => c.IsPrivate;
cfg.ShouldUseConstructor = c => c.IsPrivate;
cfg.CreateMap<Source, Destination>();
});

Expand All @@ -89,7 +89,7 @@ public void Should_only_map_private_ctor()
}
}

public class ShouldMapConstructorPublic : NonValidatingSpecBase
public class ShouldUseConstructorPublic : NonValidatingSpecBase
{
class Destination
{
Expand Down Expand Up @@ -119,7 +119,7 @@ class Source
protected override MapperConfiguration Configuration { get; } = new MapperConfiguration(
cfg =>
{
cfg.ShouldMapConstructor = c => c.IsPublic;
cfg.ShouldUseConstructor = c => c.IsPublic;
cfg.CreateMap<Source, Destination>();
});

Expand All @@ -132,7 +132,7 @@ public void Should_only_map_public_ctor()
}


public class ShouldMapConstructorDefault : AutoMapperSpecBase
public class ShouldUseConstructorDefault : AutoMapperSpecBase
{
class Destination
{
Expand Down