Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
667a3d5
use Enum.Parse<TEnum>
lbargaoanu Jul 30, 2022
77086e8
less allocations
lbargaoanu Jul 31, 2022
e3aecd3
reuse the execution plan between user Map calls and internal Map calls
lbargaoanu Aug 1, 2022
6581906
remove IObjectMapperInfo
lbargaoanu Aug 2, 2022
5f0cebd
use the more efficient Expression.Invoke instead of ConvertReplacePar…
lbargaoanu Aug 3, 2022
9fc7cdf
less allocations
lbargaoanu Aug 3, 2022
7fdf915
less null checks
lbargaoanu Aug 4, 2022
4b507ee
unreachable, As maps are sealed by default
lbargaoanu Aug 6, 2022
84e3fff
less allocations
lbargaoanu Aug 6, 2022
b5cc0a6
don't try to match ignored members
lbargaoanu Aug 7, 2022
df48e72
more efficient
lbargaoanu Aug 7, 2022
12eaef9
drop RegEx
lbargaoanu Aug 8, 2022
06b0713
docs
lbargaoanu Aug 8, 2022
dc7e58f
cosmetic
lbargaoanu Aug 8, 2022
9356388
less allocations
lbargaoanu Aug 8, 2022
39fccd9
cosmetic
lbargaoanu Aug 9, 2022
a3ae964
less allocations
lbargaoanu Aug 9, 2022
00d29ee
we don't need to create As type maps
lbargaoanu Aug 11, 2022
c9bceef
remove ITypeMapConfiguration
lbargaoanu Aug 11, 2022
a0988d7
cosmetic
lbargaoanu Aug 11, 2022
0b9cf8c
try to show a better error message when mapping records through const…
lbargaoanu Aug 11, 2022
b9699dd
less allocations
lbargaoanu Aug 13, 2022
ed9097f
special case the defaults for naming conventions
lbargaoanu Aug 13, 2022
93576ef
make TypeMapPlanBuilder a struct
lbargaoanu Aug 15, 2022
3adb02f
use readonly record struct
lbargaoanu Aug 15, 2022
7720ac8
assume that a protected constructor with CompilerGeneratedAttribute m…
lbargaoanu Aug 15, 2022
4e1117f
less allocations
lbargaoanu Aug 15, 2022
dac3062
rename configurationProvider to the shorter configuration in most places
lbargaoanu Aug 17, 2022
b24560f
less allocations
lbargaoanu Aug 17, 2022
953d66d
converters with no source should throw
lbargaoanu Aug 17, 2022
ebd2c43
less allocations
lbargaoanu Aug 18, 2022
c5d7c36
cosmetic
lbargaoanu Aug 18, 2022
12676dd
less allocations
lbargaoanu Aug 19, 2022
85ff705
make MapFrom name more like the built-in mapping
lbargaoanu Aug 19, 2022
c71f168
less allocations
lbargaoanu Aug 20, 2022
3de255f
cosmetic
lbargaoanu Aug 21, 2022
6925737
use profiles in the benchmark
lbargaoanu Aug 21, 2022
08ec72a
simplify conventions
lbargaoanu Aug 21, 2022
e9287a2
merge the profile member configuration with the global one
lbargaoanu Aug 21, 2022
0d2aa50
cosmetic
lbargaoanu Aug 22, 2022
ec0a832
test reusing the execution plan
lbargaoanu Aug 22, 2022
593ad53
refactor test base classes
lbargaoanu Aug 22, 2022
806e73f
cosmetic
lbargaoanu Aug 23, 2022
d0e0e24
avoid changing the resolver configuration objects because they're reu…
lbargaoanu Aug 31, 2022
77e0015
cosmetic
lbargaoanu Aug 31, 2022
20c283a
less allocations
lbargaoanu Sep 3, 2022
66f0020
cosmetic
lbargaoanu Sep 3, 2022
f1655e1
file scoped namespaces
lbargaoanu Sep 3, 2022
288c4ad
global usings
lbargaoanu Sep 3, 2022
e6f2ca3
cosmetic
lbargaoanu Sep 4, 2022
daacd80
less allocations
lbargaoanu Sep 10, 2022
c608787
NullMappingOrderComesFirst
lbargaoanu Sep 10, 2022
434703c
less allocations
lbargaoanu Sep 10, 2022
4ba0e5f
we could include a different constructor
lbargaoanu Sep 10, 2022
b98273e
less allocations
lbargaoanu Sep 10, 2022
7eeaf59
cosmetic
lbargaoanu Sep 11, 2022
efd1df9
allocate _runtimeTypeDetails lazily
lbargaoanu Sep 12, 2022
3a491a3
create the projection builder lazily
lbargaoanu Sep 12, 2022
7da36f6
cosmetic
lbargaoanu Sep 12, 2022
970ab2d
an adhoc fix for including open generic config
lbargaoanu Sep 14, 2022
e7ba023
cosmetic
lbargaoanu Sep 18, 2022
2b99e96
MapFrom should override ignore
lbargaoanu Sep 18, 2022
3f8448a
UseDestinationValueNullable
lbargaoanu Sep 19, 2022
8b83aa7
cosmetic
lbargaoanu Sep 21, 2022
5e0066e
avoid LINQ
lbargaoanu Sep 23, 2022
7d65b78
the destination type name is already in the error message
lbargaoanu Sep 24, 2022
3c2d8cd
cosmetic
lbargaoanu Sep 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
drop RegEx
  • Loading branch information
lbargaoanu committed Aug 8, 2022
commit 12eaef9644124b555f3f583c3f51a4bf46b29586
9 changes: 8 additions & 1 deletion src/AutoMapper/ApiCompatBaseline.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
Compat issues with assembly AutoMapper:
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.AutoMapAttribute' changed from '[AttributeUsageAttribute(1036, AllowMultiple=true)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct, AllowMultiple=true)]' in the implementation.
MembersMustExist : Member 'public System.String AutoMapper.ExactMatchNamingConvention.ReplaceValue(System.Text.RegularExpressions.Match)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Text.RegularExpressions.Regex AutoMapper.ExactMatchNamingConvention.SplittingExpression.get()' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public TMappingExpression AutoMapper.IMappingExpressionBase<TSource, TDestination, TMappingExpression>.AsProxy()' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public void AutoMapper.IMappingExpressionBase<TSource, TDestination, TMappingExpression>.AsProxy()' is present in the contract but not in the implementation.
MembersMustExist : Member 'public void AutoMapper.IMappingExpressionBase<TSource, TDestination, TMappingExpression>.AsProxy()' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Text.RegularExpressions.Regex AutoMapper.INamingConvention.SplittingExpression' is present in the contract but not in the implementation.
InterfacesShouldHaveSameMembers : Interface member 'public System.String AutoMapper.INamingConvention.ReplaceValue(System.Text.RegularExpressions.Match)' is present in the contract but not in the implementation.
MembersMustExist : Member 'public System.String AutoMapper.INamingConvention.ReplaceValue(System.Text.RegularExpressions.Match)' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.String[] AutoMapper.INamingConvention.Split(System.String)' is present in the implementation but not in the contract.
InterfacesShouldHaveSameMembers : Interface member 'public System.Text.RegularExpressions.Regex AutoMapper.INamingConvention.SplittingExpression.get()' is present in the contract but not in the implementation.
MembersMustExist : Member 'public System.Text.RegularExpressions.Regex AutoMapper.INamingConvention.SplittingExpression.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.String AutoMapper.LowerUnderscoreNamingConvention.ReplaceValue(System.Text.RegularExpressions.Match)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Text.RegularExpressions.Regex AutoMapper.LowerUnderscoreNamingConvention.SplittingExpression.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.String AutoMapper.PascalCaseNamingConvention.ReplaceValue(System.Text.RegularExpressions.Match)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Text.RegularExpressions.Regex AutoMapper.PascalCaseNamingConvention.SplittingExpression.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public AutoMapper.IMappingOperationOptions AutoMapper.ResolutionContext.Options.get()' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'AutoMapper.ValueResolverConfiguration' does not exist in the implementation but it does exist in the contract.
InterfacesShouldHaveSameMembers : Default interface member 'public System.Boolean AutoMapper.Configuration.IPropertyMapConfiguration.Ignored' is present in the implementation but not in the contract.
Expand All @@ -32,4 +39,4 @@ MembersMustExist : Member 'public AutoMapper.Internal.TypePair AutoMapper.Intern
MembersMustExist : Member 'public System.Linq.IQueryable<TDestination> AutoMapper.QueryableExtensions.Extensions.Map<TSource, TDestination>(System.Linq.IQueryable<TSource>, System.Linq.IQueryable<TDestination>, AutoMapper.IConfigurationProvider)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'public System.Collections.Generic.IReadOnlyCollection<System.Reflection.MemberInfo> AutoMapper.QueryableExtensions.MemberVisitor.MemberPath.get()' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'AutoMapper.QueryableExtensions.Impl.MemberAccessQueryMapperVisitor' does not exist in the implementation but it does exist in the contract.
Total Issues: 33
Total Issues: 40
29 changes: 13 additions & 16 deletions src/AutoMapper/Configuration/Conventions/MemberConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,26 @@ public bool MapDestinationPropertyToSource(ProfileMap options, TypeDetails sourc
{
var destinationMemberNamingConvention = isReverseMap ? SourceMemberNamingConvention : DestinationMemberNamingConvention;
var sourceMemberNamingConvention = isReverseMap ? DestinationMemberNamingConvention : SourceMemberNamingConvention;
var matches = destinationMemberNamingConvention.SplittingExpression?.Matches(nameToSearch);
if (matches == null || matches.Count < 2)
var matches = destinationMemberNamingConvention.Split(nameToSearch);
var length = matches.Length;
var separator = sourceMemberNamingConvention.SeparatorCharacter;
for (var index = 1; index <= length; index++)
{
return false;
}
MemberInfo matchingMemberInfo = null;
for (var index = 1; index <= matches.Count; index++)
{
var first = string.Join(sourceMemberNamingConvention.SeparatorCharacter, matches.Take(index).Select(m=>m.Value));
matchingMemberInfo = parent.NameMapper.GetMatchingMemberInfo(sourceType, destType, destMemberType, first);
var first = string.Join(separator, matches, 0, index);
var matchingMemberInfo = parent.NameMapper.GetMatchingMemberInfo(sourceType, destType, destMemberType, first);
if (matchingMemberInfo != null)
{
resolvers.Add(matchingMemberInfo);
var details = options.CreateTypeDetails(matchingMemberInfo.GetMemberType());
var second = string.Join(sourceMemberNamingConvention.SeparatorCharacter, matches.Skip(index).Select(m=>m.Value));
var foundMatch = parent.MapDestinationPropertyToSource(options, details, destType, destMemberType, second, resolvers, isReverseMap);
if (!foundMatch)
resolvers.RemoveAt(resolvers.Count - 1);
else
break;
var second = string.Join(separator, matches, index, length - index);
if (parent.MapDestinationPropertyToSource(options, details, destType, destMemberType, second, resolvers, isReverseMap))
{
return true;
}
resolvers.RemoveAt(resolvers.Count - 1);
}
}
return matchingMemberInfo != null;
return false;
}
}
}
39 changes: 28 additions & 11 deletions src/AutoMapper/Configuration/INamingConvention.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
using System.Text.RegularExpressions;
using System;
using System.Collections.Generic;
namespace AutoMapper
{
/// <summary>
/// Defines a naming convention strategy
/// </summary>
public interface INamingConvention
{
/// <summary>
/// Regular expression on how to tokenize a member
/// </summary>
Regex SplittingExpression { get; }
string[] Split(string input);
string SeparatorCharacter { get; }
}
public class ExactMatchNamingConvention : INamingConvention
{
public static readonly ExactMatchNamingConvention Instance = new();
public Regex SplittingExpression { get; }
public string SeparatorCharacter => "";
public string[] Split(string _) => Array.Empty<string>();
public string SeparatorCharacter => null;
}
public class PascalCaseNamingConvention : INamingConvention
{
private static readonly Regex PascalCase = new(@"(\p{Lu}+(?=$|\p{Lu}[\p{Ll}0-9])|\p{Lu}?[\p{Ll}0-9]+)");
public static readonly PascalCaseNamingConvention Instance = new();
public Regex SplittingExpression { get; } = PascalCase;
public string SeparatorCharacter => "";
public string[] Split(string input)
{
List<string> result = null;
int lower = 0;
int index = 1;
while (index < input.Length)
{
if (char.IsUpper(input[index]))
{
result ??= new();
result.Add(input[lower..index]);
lower = index;
}
index++;
}
if (result == null)
{
return Array.Empty<string>();
}
result.Add(input[lower..index]);
return result.ToArray();
}
}
public class LowerUnderscoreNamingConvention : INamingConvention
{
private static readonly Regex LowerUnderscore = new(@"[\p{Ll}\p{Lu}0-9]+(?=_?)");
public static readonly LowerUnderscoreNamingConvention Instance = new();
public Regex SplittingExpression { get; } = LowerUnderscore;
public string SeparatorCharacter => "_";
public string[] Split(string input) => input.Split('_', StringSplitOptions.RemoveEmptyEntries);
}
}
6 changes: 2 additions & 4 deletions src/UnitTests/Internal/TypeMapFactorySpecs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Xunit;
using Shouldly;
Expand All @@ -11,7 +8,6 @@ namespace AutoMapper.UnitTests.Tests
{
using AutoMapper.Internal;
using System;
using Assembly = System.Reflection.Assembly;

public class StubNamingConvention : INamingConvention
{
Expand All @@ -26,6 +22,8 @@ public StubNamingConvention(Func<Match, string> replaceFunc)
public Regex SplittingExpression { get; set; }
public string SeparatorCharacter { get; set; }

public string[] Split(string input) => SplittingExpression.Matches(input).Select(m=>m.Value).ToArray();

public string ReplaceValue(Match match)
{
return _replaceFunc(match);
Expand Down
5 changes: 1 addition & 4 deletions src/UnitTests/ReverseMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,7 @@ public class UnderscoreNamingConvention : INamingConvention
public Regex SplittingExpression { get; } = new Regex(@"\p{Lu}[a-z0-9]*(?=_?)");

public string SeparatorCharacter => "_";
public string ReplaceValue(Match match)
{
return match.Value;
}
public string[] Split(string input) => SplittingExpression.Matches(input).Select(m => m.Value).ToArray();
}

protected override MapperConfiguration CreateConfiguration() => new(cfg =>
Expand Down