Skip to content

Commit

Permalink
Final inheritance support version!
Browse files Browse the repository at this point in the history
  • Loading branch information
yanisimov committed Jan 18, 2017
1 parent 3f41815 commit 78550a8
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 62 deletions.
6 changes: 3 additions & 3 deletions ExpressMapper NET40/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.3.0")]
[assembly: AssemblyFileVersion("1.8.3.0")]
[assembly: AssemblyInformationalVersion("1.8.3")]
[assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
[assembly: AssemblyInformationalVersion("1.9.0")]
50 changes: 27 additions & 23 deletions ExpressMapper NETCORE/MappingServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ private IMemberConfiguration<T, TN> RegisterInternal<T, TN>(bool memberCaseInsen
var sourceClassMapper = new SourceTypeMapper<T, TN>(SourceService, this);
var destinationClassMapper = new DestinationTypeMapper<T, TN>(DestinationService, this);

SourceService.TypeMappers[cacheKey] = sourceClassMapper;
DestinationService.TypeMappers[cacheKey] = destinationClassMapper;
var memberConfiguration = new MemberConfiguration<T, TN>(
new ITypeMapper<T, TN>[] {sourceClassMapper, destinationClassMapper}, this);
sourceClassMapper.MemberConfiguration = memberConfiguration;
destinationClassMapper.MemberConfiguration = memberConfiguration;

if (!CustomMappingsBySource.ContainsKey(src.GetHashCode()))
{
CustomMappingsBySource[src.GetHashCode()] = new List<long>();
Expand All @@ -141,12 +148,6 @@ private IMemberConfiguration<T, TN> RegisterInternal<T, TN>(bool memberCaseInsen
CustomMappingsBySource[src.GetHashCode()].Add(cacheKey);
}

SourceService.TypeMappers[cacheKey] = sourceClassMapper;
DestinationService.TypeMappers[cacheKey] = destinationClassMapper;
var memberConfiguration = new MemberConfiguration<T, TN>(
new ITypeMapper<T, TN>[] {sourceClassMapper, destinationClassMapper}, this);
sourceClassMapper.MemberConfiguration = memberConfiguration;
destinationClassMapper.MemberConfiguration = memberConfiguration;
return memberConfiguration;
}
}
Expand Down Expand Up @@ -385,25 +386,39 @@ private object MapNonGenericInternal(Type srcType, Type dstType, object src, obj
{
return null;
}

var cacheKey = CalculateCacheKey(srcType, dstType);
if (CustomMappers.ContainsKey(cacheKey))
{
var customTypeMapper = CustomMappers[cacheKey];
var typeMapper = customTypeMapper();
if (!_customTypeMapperCache.ContainsKey(cacheKey))
{
CompileNonGenericCustomTypeMapper(srcType, dstType, typeMapper, cacheKey);
}
return _customTypeMapperCache[cacheKey](src, dest);
}

ITypeMapper mapper = null;
var actualSrcType = src.GetType();
if (srcType != actualSrcType && actualSrcType.IsAssignableFrom(srcType))
if (srcType != actualSrcType && actualSrcType.GetInfo().IsAssignableFrom(srcType))
throw new InvalidCastException($"Your source object instance type '{actualSrcType.FullName}' is not assignable from source type you specified '{srcType}'.");

var srcHash = actualSrcType.GetHashCode();

if (dest != null)
{
var actualDstType = dest.GetType();
if (dstType != actualDstType && actualDstType.IsAssignableFrom(dstType))
if (dstType != actualDstType && actualDstType.GetInfo().IsAssignableFrom(dstType))
throw new InvalidCastException($"Your destination object instance type '{actualSrcType.FullName}' is not assignable from destination type you specified '{srcType}'.");

if (CustomMappingsBySource.ContainsKey(srcHash))
{
var mappings = CustomMappingsBySource[srcHash];

mapper =
mappings.Select(m => DestinationService.TypeMappers[m])
mappings.Where(m => DestinationService.TypeMappers.ContainsKey(m))
.Select(m => DestinationService.TypeMappers[m])
.FirstOrDefault(tm => tm.DestinationType == actualDstType);
}
}
Expand All @@ -413,8 +428,9 @@ private object MapNonGenericInternal(Type srcType, Type dstType, object src, obj
{
var mappings = CustomMappingsBySource[srcHash];
var typeMappers =
mappings.Select(m => SourceService.TypeMappers[m])
.Where(m => dstType.IsAssignableFrom(m.DestinationType))
mappings.Where(m => SourceService.TypeMappers.ContainsKey(m))
.Select(m => SourceService.TypeMappers[m])
.Where(m => dstType.GetInfo().IsAssignableFrom(m.DestinationType))
.ToList();
if (typeMappers.Count > 1)
{
Expand All @@ -432,18 +448,6 @@ private object MapNonGenericInternal(Type srcType, Type dstType, object src, obj
}
}

var cacheKey = CalculateCacheKey(srcType, dstType);
if (CustomMappers.ContainsKey(cacheKey))
{
var customTypeMapper = CustomMappers[cacheKey];
var typeMapper = customTypeMapper();
if (!_customTypeMapperCache.ContainsKey(cacheKey))
{
CompileNonGenericCustomTypeMapper(srcType, dstType, typeMapper, cacheKey);
}
return _customTypeMapperCache[cacheKey](src, dest);
}

var mappingService = dest == null ? SourceService : DestinationService;
if (mapper != null)
{
Expand Down
6 changes: 3 additions & 3 deletions ExpressMapper NETCORE/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("969e6614-0489-4174-a735-cc66f51d8746")]

[assembly: AssemblyVersion("1.8.3.0")]
[assembly: AssemblyFileVersion("1.8.3.0")]
[assembly: AssemblyInformationalVersion("1.8.3")]
[assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
[assembly: AssemblyInformationalVersion("1.9.0")]
10 changes: 5 additions & 5 deletions ExpressMapper NETCORE/TypeMapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void Compile(CompilationTypes compilationType, bool forceByDemand = false
catch (Exception ex)
{
throw new ExpressmapperException(
$"Error error occured trying to compile mapping for: source {typeof(T).FullName}, destination {typeof(TN).FullName}. See the inner exception for details.",
$"Error error occured trying to compile mapping for: source {typeof (T).FullName}, destination {typeof (TN).FullName}. See the inner exception for details.",
ex);
}
}
Expand Down Expand Up @@ -291,9 +291,9 @@ protected void ProcessAutoProperties()

var stringComparison = GetStringCase();

// var comparer = CultureInfo.CurrentCulture.CompareInfo.GetStringComparer(CompareOptions.OrdinalIgnoreCase);
var comparer = StringComparer.Create(CultureInfo.CurrentCulture,
stringComparison == StringComparison.OrdinalIgnoreCase);
var comparer = CultureInfo.CurrentCulture.CompareInfo.GetStringComparer(CompareOptions.OrdinalIgnoreCase);
//var comparer = StringComparer.Create(CultureInfo.CurrentCulture,
// stringComparison == StringComparison.OrdinalIgnoreCase);

foreach (var prop in sourceMembers)
{
Expand Down Expand Up @@ -527,7 +527,7 @@ public ReplaceMemberTypeVisitor(Type replacementType, Expression instanceExp)

protected override Expression VisitMember(MemberExpression node)
{
return node.Member.DeclaringType.IsAssignableFrom(_replacementType)
return node.Member.DeclaringType.GetInfo().IsAssignableFrom(_replacementType)
? Expression.PropertyOrField(_instanceExp, node.Member.Name)
: base.VisitMember(node);
}
Expand Down
3 changes: 2 additions & 1 deletion ExpressMapper NETCORE/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"version": "1.0.0-*",
"buildOptions": {
"outputName": "ExpressMapper"
"outputName": "ExpressMapper",
"xmlDoc": true
},

"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions ExpressMapper Net46/ExpressMapper Net46.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\ExpressMapper.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand Down
1 change: 1 addition & 0 deletions ExpressMapper PCL NET45/ExpressMapper PCL NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\ExpressMapper.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand Down
6 changes: 3 additions & 3 deletions ExpressMapper PCL NET45/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.3.0")]
[assembly: AssemblyFileVersion("1.8.3.0")]
[assembly: AssemblyInformationalVersion("1.8.3.0")]
[assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
[assembly: AssemblyInformationalVersion("1.9.0.0")]
50 changes: 27 additions & 23 deletions Expressmapper.Shared/MappingServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ private IMemberConfiguration<T, TN> RegisterInternal<T, TN>(bool memberCaseInsen
var sourceClassMapper = new SourceTypeMapper<T, TN>(SourceService, this);
var destinationClassMapper = new DestinationTypeMapper<T, TN>(DestinationService, this);

SourceService.TypeMappers[cacheKey] = sourceClassMapper;
DestinationService.TypeMappers[cacheKey] = destinationClassMapper;
var memberConfiguration = new MemberConfiguration<T, TN>(
new ITypeMapper<T, TN>[] { sourceClassMapper, destinationClassMapper }, this);
sourceClassMapper.MemberConfiguration = memberConfiguration;
destinationClassMapper.MemberConfiguration = memberConfiguration;

if (!CustomMappingsBySource.ContainsKey(src.GetHashCode()))
{
CustomMappingsBySource[src.GetHashCode()] = new List<long>();
Expand All @@ -141,12 +148,6 @@ private IMemberConfiguration<T, TN> RegisterInternal<T, TN>(bool memberCaseInsen
CustomMappingsBySource[src.GetHashCode()].Add(cacheKey);
}

SourceService.TypeMappers[cacheKey] = sourceClassMapper;
DestinationService.TypeMappers[cacheKey] = destinationClassMapper;
var memberConfiguration = new MemberConfiguration<T, TN>(
new ITypeMapper<T, TN>[] {sourceClassMapper, destinationClassMapper}, this);
sourceClassMapper.MemberConfiguration = memberConfiguration;
destinationClassMapper.MemberConfiguration = memberConfiguration;
return memberConfiguration;
}
}
Expand Down Expand Up @@ -385,25 +386,39 @@ private object MapNonGenericInternal(Type srcType, Type dstType, object src, obj
{
return null;
}

var cacheKey = CalculateCacheKey(srcType, dstType);
if (CustomMappers.ContainsKey(cacheKey))
{
var customTypeMapper = CustomMappers[cacheKey];
var typeMapper = customTypeMapper();
if (!_customTypeMapperCache.ContainsKey(cacheKey))
{
CompileNonGenericCustomTypeMapper(srcType, dstType, typeMapper, cacheKey);
}
return _customTypeMapperCache[cacheKey](src, dest);
}

ITypeMapper mapper = null;
var actualSrcType = src.GetType();
if (srcType != actualSrcType && actualSrcType.IsAssignableFrom(srcType))
if (srcType != actualSrcType && actualSrcType.GetInfo().IsAssignableFrom(srcType))
throw new InvalidCastException($"Your source object instance type '{actualSrcType.FullName}' is not assignable from source type you specified '{srcType}'.");

var srcHash = actualSrcType.GetHashCode();

if (dest != null)
{
var actualDstType = dest.GetType();
if (dstType != actualDstType && actualDstType.IsAssignableFrom(dstType))
if (dstType != actualDstType && actualDstType.GetInfo().IsAssignableFrom(dstType))
throw new InvalidCastException($"Your destination object instance type '{actualSrcType.FullName}' is not assignable from destination type you specified '{srcType}'.");

if (CustomMappingsBySource.ContainsKey(srcHash))
{
var mappings = CustomMappingsBySource[srcHash];

mapper =
mappings.Select(m => DestinationService.TypeMappers[m])
mappings.Where(m => DestinationService.TypeMappers.ContainsKey(m))
.Select(m => DestinationService.TypeMappers[m])
.FirstOrDefault(tm => tm.DestinationType == actualDstType);
}
}
Expand All @@ -413,8 +428,9 @@ private object MapNonGenericInternal(Type srcType, Type dstType, object src, obj
{
var mappings = CustomMappingsBySource[srcHash];
var typeMappers =
mappings.Select(m => SourceService.TypeMappers[m])
.Where(m => dstType.IsAssignableFrom(m.DestinationType))
mappings.Where(m => SourceService.TypeMappers.ContainsKey(m))
.Select(m => SourceService.TypeMappers[m])
.Where(m => dstType.GetInfo().IsAssignableFrom(m.DestinationType))
.ToList();
if (typeMappers.Count > 1)
{
Expand All @@ -432,18 +448,6 @@ private object MapNonGenericInternal(Type srcType, Type dstType, object src, obj
}
}

var cacheKey = CalculateCacheKey(srcType, dstType);
if (CustomMappers.ContainsKey(cacheKey))
{
var customTypeMapper = CustomMappers[cacheKey];
var typeMapper = customTypeMapper();
if (!_customTypeMapperCache.ContainsKey(cacheKey))
{
CompileNonGenericCustomTypeMapper(srcType, dstType, typeMapper, cacheKey);
}
return _customTypeMapperCache[cacheKey](src, dest);
}

var mappingService = dest == null ? SourceService : DestinationService;
if (mapper != null)
{
Expand Down
2 changes: 1 addition & 1 deletion Expressmapper.Shared/TypeMapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public ReplaceMemberTypeVisitor(Type replacementType, Expression instanceExp)

protected override Expression VisitMember(MemberExpression node)
{
return node.Member.DeclaringType.IsAssignableFrom(_replacementType)
return node.Member.DeclaringType.GetInfo().IsAssignableFrom(_replacementType)
? Expression.PropertyOrField(_instanceExp, node.Member.Name)
: base.VisitMember(node);
}
Expand Down

0 comments on commit 78550a8

Please sign in to comment.