Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions Slapper.AutoMapper.Tests/Slapper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 1 addition & 1 deletion Slapper.AutoMapper.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net4" userInstalled="true" />
<package id="NUnitTestAdapter" version="2.1.1" targetFramework="net40" userInstalled="true" />
</packages>
13 changes: 8 additions & 5 deletions Slapper.AutoMapper/Slapper.AutoMapper.InternalHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dynamic data into static types and populate complex nested child objects.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
Expand All @@ -49,6 +50,8 @@ public static partial class AutoMapper
/// </summary>
internal static class InternalHelpers
{

private static CultureInfo cultureInfo = CultureInfo.InvariantCulture;
/// <summary>
/// Combine several hashcodes into a single new one. This implementation was grabbed from http://stackoverflow.com/a/34229665 where it is introduced
/// as MS implementation of GetHashCode() for strings.
Expand Down Expand Up @@ -202,7 +205,7 @@ public static Cache.TypeMap CreateTypeMap(Type type)
{
identifiers.Add(memberName);
}
else if (conventionIdentifiers.Exists(x => x.ToLower() == memberName.ToLower()))
else if (conventionIdentifiers.Exists(x => x.ToLower(cultureInfo) == memberName.ToLower(cultureInfo)))
{
identifiers.Add(memberName);
}
Expand All @@ -217,7 +220,7 @@ public static Cache.TypeMap CreateTypeMap(Type type)
{
identifiers.Add(memberName);
}
else if (conventionIdentifiers.Exists(x => x.ToLower() == memberName.ToLower()))
else if (conventionIdentifiers.Exists(x => x.ToLower(cultureInfo) == memberName.ToLower(cultureInfo)))
{
identifiers.Add(memberName);
}
Expand Down Expand Up @@ -486,7 +489,7 @@ internal static object Map(IDictionary<string, object> dictionary, object instan

foreach (var fieldOrProperty in fieldsAndProperties)
{
var memberName = fieldOrProperty.Key.ToLower();
var memberName = fieldOrProperty.Key.ToLower(cultureInfo);

var member = fieldOrProperty.Value;

Expand All @@ -505,7 +508,7 @@ internal static object Map(IDictionary<string, object> dictionary, object instan
if (memberType.IsClass || memberType.IsInterface)
{
// Try to find any keys that start with the current member name
var nestedDictionary = dictionary.Where(x => x.Key.ToLower().StartsWith(memberName + "_")).ToList();
var nestedDictionary = dictionary.Where(x => x.Key.ToLower(cultureInfo).StartsWith(memberName + "_")).ToList();

// If there weren't any keys
if (!nestedDictionary.Any())
Expand All @@ -524,7 +527,7 @@ internal static object Map(IDictionary<string, object> dictionary, object instan
continue;
}
var regex = new Regex(Regex.Escape(memberName + "_"));
var newDictionary = nestedDictionary.ToDictionary(pair => regex.Replace(pair.Key.ToLower(), string.Empty, 1),
var newDictionary = nestedDictionary.ToDictionary(pair => regex.Replace(pair.Key.ToLower(cultureInfo), string.Empty, 1),
pair => pair.Value, StringComparer.OrdinalIgnoreCase);

// Try to get the value of the complex member. If the member
Expand Down