Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Adding coarse lock to inline map creation; restoring cache
  • Loading branch information
jbogard committed Nov 15, 2017
commit 48d9dc0149430a11e47207d2ae92a70c0cb8a74b
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace AutoMapper.Configuration.Conventions
{
public class SourceToDestinationNameMapperAttributesMember : ISourceToDestinationNameMapper
{
private static readonly SourceMember[] Empty = new SourceMember[0];
private readonly Dictionary<TypeDetails, SourceMember[]> _allSourceMembers = new Dictionary<TypeDetails, SourceMember[]>();

public MemberInfo GetMatchingMemberInfo(IGetTypeInfoMembers getTypeInfoMembers, TypeDetails typeInfo, Type destType, Type destMemberType, string nameToSearch)
{
var sourceMembers = getTypeInfoMembers.GetMemberInfos(typeInfo)
.Select(sourceMember => new SourceMember(sourceMember))
.Where(s => s.Attribute != null)
.ToArray();

if (!_allSourceMembers.TryGetValue(typeInfo, out SourceMember[] sourceMembers))
{
sourceMembers = getTypeInfoMembers.GetMemberInfos(typeInfo).Select(sourceMember => new SourceMember(sourceMember)).Where(s => s.Attribute != null).ToArray();
_allSourceMembers[typeInfo] = sourceMembers.Length == 0 ? Empty : sourceMembers;
}
return sourceMembers.FirstOrDefault(d => d.Attribute.IsMatch(typeInfo, d.Member, destType, destMemberType, nameToSearch)).Member;
}

Expand Down
5 changes: 4 additions & 1 deletion src/AutoMapper/MapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ private TypeMap GetTypeMap(TypePair initialTypes)
&& !ExcludedTypes.Contains(initialTypes.SourceType)
&& !ExcludedTypes.Contains(initialTypes.DestinationType))
{
return Configuration.CreateInlineMap(_typeMapRegistry, initialTypes);
lock (this)
{
return Configuration.CreateInlineMap(_typeMapRegistry, initialTypes);
}
}

return null;
Expand Down