Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jbogard committed Feb 18, 2013
2 parents 2c402b0 + 77340f5 commit 7b882fb
Show file tree
Hide file tree
Showing 42 changed files with 1,780 additions and 873 deletions.
12 changes: 6 additions & 6 deletions default.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ properties {
$test_dir = "$build_dir\test"
$result_dir = "$build_dir\results"
$lib_dir = "$base_dir\lib"
$version = if ($env:build_number -ne $NULL) { $env:build_number } else { '2.1.0' }
$pkgVersion = if ($env:build_number -ne $NULL) { $env:build_number } else { '2.2.1' }
$version = $pkgVersion -replace "-.*$", ""
$buildNumber = $version + '.0'
$global:config = "debug"
$framework_dir = Get-FrameworkDirectory
Expand All @@ -35,7 +36,7 @@ task compile -depends clean {
}

task commonAssemblyInfo {
$commit = git log -1 --pretty=format:%H
$commit = if ($env:BUILD_VCS_NUMBER -ne $NULL) { $env:BUILD_VCS_NUMBER } else { git log -1 --pretty=format:%H }
create-commonAssemblyInfo "$buildNumber" "$commit" "$source_dir\CommonAssemblyInfo.cs"
}

Expand All @@ -47,8 +48,7 @@ task test {
task dist {
create_directory $dist_dir
copy_files "$build_dir\$config\AutoMapper" "$dist_dir\net40-client"
create-nuspec "$version" "AutoMapper.nuspec"
create-nuspec "$version-ci" "AutoMapper-CI.nuspec"
create-nuspec "$pkgVersion" "AutoMapper.nuspec"
}

# -------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -115,10 +115,10 @@ using System.Runtime.InteropServices;
[assembly: AssemblyFileVersionAttribute(""$version"")]
[assembly: AssemblyCopyrightAttribute(""Copyright Jimmy Bogard 2008-" + $date.Year + """)]
[assembly: AssemblyProductAttribute(""AutoMapper"")]
[assembly: AssemblyTrademarkAttribute(""$commit"")]
[assembly: AssemblyTrademarkAttribute(""AutoMapper"")]
[assembly: AssemblyCompanyAttribute("""")]
[assembly: AssemblyConfigurationAttribute(""release"")]
[assembly: AssemblyInformationalVersionAttribute(""$version"")]" | out-file $filename -encoding "ASCII"
[assembly: AssemblyInformationalVersionAttribute(""$commit"")]" | out-file $filename -encoding "ASCII"
}

function global:create-nuspec($version, $fileName)
Expand Down
427 changes: 214 additions & 213 deletions src/AutoMapper/AutoMapper.csproj

Large diffs are not rendered by default.

164 changes: 82 additions & 82 deletions src/AutoMapper/AutoMapperMappingException.cs
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace AutoMapper
{
#if !SILVERLIGHT
[Serializable]
#endif
public class AutoMapperMappingException : Exception
{
private string _message;

//
// For guidelines regarding the creation of new exception types, see
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
// and
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
//

public AutoMapperMappingException()
{
}

public AutoMapperMappingException(string message)
: base(message)
{
_message = message;
}

public AutoMapperMappingException(string message, Exception inner)
: base(null, inner)
{
_message = message;
}

public AutoMapperMappingException(ResolutionContext context)
{
Context = context;
}

public AutoMapperMappingException(ResolutionContext context, Exception inner)
: base(null, inner)
{
Context = context;
}

#if !SILVERLIGHT
protected AutoMapperMappingException(
SerializationInfo info,
StreamingContext context) : base(info, context)
{
}
#endif

public AutoMapperMappingException(ResolutionContext context, string message)
: this(context)
{
_message = message;
}

public ResolutionContext Context { get; private set; }

public override string Message
{
get
{
string message = null;
namespace AutoMapper
{
#if !SILVERLIGHT
[Serializable]
#endif
public class AutoMapperMappingException : Exception
{
private string _message;

//
// For guidelines regarding the creation of new exception types, see
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
// and
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
//

public AutoMapperMappingException()
{
}

public AutoMapperMappingException(string message)
: base(message)
{
_message = message;
}

public AutoMapperMappingException(string message, Exception inner)
: base(null, inner)
{
_message = message;
}

public AutoMapperMappingException(ResolutionContext context)
{
Context = context;
}

public AutoMapperMappingException(ResolutionContext context, Exception inner)
: base(null, inner)
{
Context = context;
}

#if !SILVERLIGHT
protected AutoMapperMappingException(
SerializationInfo info,
StreamingContext context) : base(info, context)
{
}
#endif

public AutoMapperMappingException(ResolutionContext context, string message)
: this(context)
{
_message = message;
}

public ResolutionContext Context { get; private set; }

public override string Message
{
get
{
string message = null;
var newLine = Environment.NewLine;
if (Context != null)
{

message = _message + "\n\nMapping types:";
message += Environment.NewLine + string.Format("{0} -> {1}", Context.SourceType.Name, Context.DestinationType.Name);
message += Environment.NewLine + string.Format("{0} -> {1}", Context.SourceType.FullName, Context.DestinationType.FullName);
message = _message + newLine + newLine + "Mapping types:";
message += newLine + string.Format("{0} -> {1}", Context.SourceType.Name, Context.DestinationType.Name);
message += newLine + string.Format("{0} -> {1}", Context.SourceType.FullName, Context.DestinationType.FullName);

var destPath = GetDestPath(Context);
message += "\n\nDestination path:\n" + destPath;
message += newLine + newLine + "Destination path:" + newLine + destPath;

message += "\n\nSource value:\n" + (Context.SourceValue ?? "(null)");
message += newLine + newLine + "Source value:" + newLine + (Context.SourceValue ?? "(null)");

return message;
}
if (_message != null)
{
message = _message;
}
if (_message != null)
{
message = _message;
}

message = (message == null ? null : message + newLine) + base.Message;

message = (message == null ? null : message + "\n") + base.Message;

return message;
}
return message;
}
}

private string GetDestPath(ResolutionContext context)
Expand Down Expand Up @@ -135,7 +135,7 @@ public override string StackTrace
.Split(new[] {Environment.NewLine}, StringSplitOptions.None)
.Where(str => !str.TrimStart().StartsWith("at AutoMapper.")));
}
}
}
#endif
}
}
}
}
44 changes: 29 additions & 15 deletions src/AutoMapper/ConfigurationStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ public bool ConstructorMappingEnabled
get { return GetProfile(DefaultProfileName).ConstructorMappingEnabled; }
}

public Assembly[] SourceExtensionMethodSearch
public bool DataReaderMapperYieldReturnEnabled
{
get { return GetProfile(DefaultProfileName).DataReaderMapperYieldReturnEnabled; }
}

public Assembly[] SourceExtensionMethodSearch
{
get { return GetProfile(DefaultProfileName).SourceExtensionMethodSearch; }
set { GetProfile(DefaultProfileName).SourceExtensionMethodSearch = value; }
Expand Down Expand Up @@ -153,7 +158,12 @@ public void DisableConstructorMapping()
GetProfile(DefaultProfileName).ConstructorMappingEnabled = false;
}

public void Seal()
public void EnableYieldReturnForDataReaderMapper()
{
GetProfile(DefaultProfileName).DataReaderMapperYieldReturnEnabled = true;
}

public void Seal()
{
_typeMaps.Each(typeMap => typeMap.Seal());
}
Expand Down Expand Up @@ -330,10 +340,10 @@ public TypeMap[] GetAllTypeMaps()

public TypeMap FindTypeMapFor(Type sourceType, Type destinationType)
{
return FindTypeMapFor( null, sourceType, destinationType ) ;
return FindTypeMapFor( null, null, sourceType, destinationType ) ;
}

public TypeMap FindTypeMapFor(object source, Type sourceType, Type destinationType)
public TypeMap FindTypeMapFor(object source, object destination, Type sourceType, Type destinationType)
{
var typeMapPair = new TypePair(sourceType, destinationType);

Expand All @@ -342,7 +352,7 @@ public TypeMap FindTypeMapFor(object source, Type sourceType, Type destinationTy
if (!_typeMapCache.TryGetValue(typeMapPair, out typeMap))
{
// Cache miss
typeMap = FindTypeMap(source, sourceType, destinationType, DefaultProfileName);
typeMap = FindTypeMap(source, destination, sourceType, destinationType, DefaultProfileName);

//We don't want to inherit base mappings which may be ambiguous or too specific resulting in cast exceptions
if (source == null || source.GetType() == sourceType)
Expand All @@ -351,12 +361,16 @@ public TypeMap FindTypeMapFor(object source, Type sourceType, Type destinationTy
// Due to the inheritance we can have derrived mapping cached which is not valid for this source object
else if (source != null && typeMap != null && !typeMap.SourceType.IsAssignableFrom(source.GetType()))
{
typeMap = FindTypeMapFor(source, source.GetType(), destinationType);
typeMap = FindTypeMapFor(source, destination, source.GetType(), destinationType);
}

if (typeMap == null && destination != null && destination.GetType() != destinationType)
{
typeMap = FindTypeMapFor(source, destination, sourceType, destination.GetType());
}
if (typeMap != null && typeMap.DestinationTypeOverride != null)
{
return FindTypeMapFor(source, sourceType, typeMap.DestinationTypeOverride);
return FindTypeMapFor(source, destination, sourceType, typeMap.DestinationTypeOverride);
}
// Check for runtime derived types
var shouldCheckDerivedType = (typeMap != null) && (typeMap.HasDerivedTypesToInclude()) && (source != null) && (source.GetType() != sourceType);
Expand Down Expand Up @@ -401,7 +415,7 @@ public TypeMap FindTypeMapFor(object source, Type sourceType, Type destinationTy
if (potentialTypeMap == null)
{
var targetSourceType = targetDestinationType != destinationType ? potentialSourceType : typeMap.SourceType;
typeMap = FindTypeMap(source, targetSourceType, targetDestinationType, DefaultProfileName);
typeMap = FindTypeMap(source, destination, targetSourceType, targetDestinationType, DefaultProfileName);
}
else
typeMap = potentialTypeMap;
Expand Down Expand Up @@ -429,8 +443,8 @@ private static IEnumerable<Type> InheritanceTree(Type type)

public TypeMap FindTypeMapFor(ResolutionResult resolutionResult, Type destinationType)
{
return FindTypeMapFor(resolutionResult.Value, resolutionResult.Type, destinationType) ??
FindTypeMapFor(resolutionResult.Value, resolutionResult.MemberType, destinationType);
return FindTypeMapFor(resolutionResult.Value, null, resolutionResult.Type, destinationType) ??
FindTypeMapFor(resolutionResult.Value, null, resolutionResult.MemberType, destinationType);
}

public IFormatterConfiguration GetProfileConfiguration(string profileName)
Expand Down Expand Up @@ -525,7 +539,7 @@ private static bool ShouldCheckMap(TypeMap typeMap)
#endif
}

private TypeMap FindTypeMap(object source, Type sourceType, Type destinationType, string profileName)
private TypeMap FindTypeMap(object source, object destination, Type sourceType, Type destinationType, string profileName)
{
TypeMap typeMap = FindExplicitlyDefinedTypeMap(sourceType, destinationType);

Expand All @@ -542,7 +556,7 @@ private TypeMap FindTypeMap(object source, Type sourceType, Type destinationType
{
foreach (var sourceInterface in sourceType.GetInterfaces())
{
typeMap = ((IConfigurationProvider)this).FindTypeMapFor(source, sourceInterface, destinationType);
typeMap = ((IConfigurationProvider)this).FindTypeMapFor(source, destination, sourceInterface, destinationType);

if (typeMap == null) continue;

Expand All @@ -556,7 +570,7 @@ private TypeMap FindTypeMap(object source, Type sourceType, Type destinationType
}

if ((sourceType.BaseType != null) && (typeMap == null))
typeMap = ((IConfigurationProvider)this).FindTypeMapFor(source, sourceType.BaseType, destinationType);
typeMap = ((IConfigurationProvider)this).FindTypeMapFor(source, destination, sourceType.BaseType, destinationType);
}
}
return typeMap;
Expand Down Expand Up @@ -600,7 +614,7 @@ private void DryRunTypeMap(ICollection<TypeMap> typeMapsChecked, ResolutionConte
{
var sourceType = lastResolver.MemberType;
var destinationType = propertyMap.DestinationProperty.MemberType;
var memberTypeMap = ((IConfigurationProvider)this).FindTypeMapFor(null, sourceType, destinationType);
var memberTypeMap = ((IConfigurationProvider)this).FindTypeMapFor(sourceType, destinationType);

if (typeMapsChecked.Any(typeMap => Equals(typeMap, memberTypeMap)))
continue;
Expand All @@ -616,7 +630,7 @@ private void DryRunTypeMap(ICollection<TypeMap> typeMapsChecked, ResolutionConte
{
Type sourceElementType = TypeHelper.GetElementType(context.SourceType);
Type destElementType = TypeHelper.GetElementType(context.DestinationType);
TypeMap itemTypeMap = ((IConfigurationProvider) this).FindTypeMapFor(null, sourceElementType, destElementType);
TypeMap itemTypeMap = ((IConfigurationProvider) this).FindTypeMapFor(sourceElementType, destElementType);

if (typeMapsChecked.Any(typeMap => Equals(typeMap, itemTypeMap)))
return;
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/IConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public TypeMapCreatedEventArgs(TypeMap typeMap)
public interface IConfigurationProvider : IProfileConfiguration
{
TypeMap[] GetAllTypeMaps();
TypeMap FindTypeMapFor(object source, Type sourceType, Type destinationType);
TypeMap FindTypeMapFor(object source, object destination, Type sourceType, Type destinationType);
TypeMap FindTypeMapFor(Type sourceType, Type destinationType);
TypeMap FindTypeMapFor(ResolutionResult resolutionResult, Type destinationType);
IFormatterConfiguration GetProfileConfiguration(string profileName);
Expand Down
2 changes: 1 addition & 1 deletion src/AutoMapper/IFormatterExpression.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Reflection;

namespace AutoMapper
{
Expand Down Expand Up @@ -49,5 +48,6 @@ public interface IConfiguration : IProfileExpression
void ConstructServicesUsing(Func<Type, object> constructor);
void DisableConstructorMapping();
void Seal();
void EnableYieldReturnForDataReaderMapper();
}
}
3 changes: 2 additions & 1 deletion src/AutoMapper/INamingConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public interface IMappingOptions
IEnumerable<string> DestinationPostfixes { get; }
IEnumerable<AliasedMember> Aliases { get; }
bool ConstructorMappingEnabled { get; }
Assembly[] SourceExtensionMethodSearch { get; set; }
bool DataReaderMapperYieldReturnEnabled { get; }
Assembly[] SourceExtensionMethodSearch { get; set; }
}

public class PascalCaseNamingConvention : INamingConvention
Expand Down
Loading

0 comments on commit 7b882fb

Please sign in to comment.