-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
namespace AutoMapper | ||
{ | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Internal; | ||
|
||
/// <summary> | ||
/// Options for matching source/destination member types | ||
/// </summary> | ||
public interface IMappingOptions | ||
{ | ||
/// <summary> | ||
/// Naming convention for source members | ||
/// </summary> | ||
INamingConvention SourceMemberNamingConvention { get; } | ||
/// <summary> | ||
/// Naming convention for destination members | ||
/// </summary> | ||
INamingConvention DestinationMemberNamingConvention { get; } | ||
/// <summary> | ||
/// Source member name prefixes to ignore/drop | ||
/// </summary> | ||
IEnumerable<string> Prefixes { get; } | ||
/// <summary> | ||
/// Source member name postfixes to ignore/drop | ||
/// </summary> | ||
IEnumerable<string> Postfixes { get; } | ||
|
||
/// <summary> | ||
/// Destination member name prefixes to ignore/drop | ||
/// </summary> | ||
IEnumerable<string> DestinationPrefixes { get; } | ||
|
||
/// <summary> | ||
/// Destination member naem prefixes to ignore/drop | ||
/// </summary> | ||
IEnumerable<string> DestinationPostfixes { get; } | ||
|
||
/// <summary> | ||
/// Source/destination member name replacers | ||
/// </summary> | ||
IEnumerable<MemberNameReplacer> MemberNameReplacers { get; } | ||
|
||
/// <summary> | ||
/// Source/destination member aliases | ||
/// </summary> | ||
IEnumerable<AliasedMember> Aliases { get; } | ||
|
||
/// <summary> | ||
/// Allow mapping to constructors that accept arguments | ||
/// </summary> | ||
bool ConstructorMappingEnabled { get; } | ||
|
||
/// <summary> | ||
/// For mapping via data readers, enable lazy returning of values instead of immediate evalaution | ||
/// </summary> | ||
bool DataReaderMapperYieldReturnEnabled { get; } | ||
|
||
/// <summary> | ||
/// Source extension methods included for search | ||
/// </summary> | ||
IEnumerable<MethodInfo> SourceExtensionMethods { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace AutoMapper | ||
{ | ||
using System.Text.RegularExpressions; | ||
|
||
public class LowerUnderscoreNamingConvention : INamingConvention | ||
{ | ||
public Regex SplittingExpression { get; } = new Regex(@"[\p{Ll}0-9]+(?=_?)"); | ||
|
||
public string SeparatorCharacter => "_"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace AutoMapper | ||
{ | ||
using System.Text.RegularExpressions; | ||
|
||
public class PascalCaseNamingConvention : INamingConvention | ||
{ | ||
public Regex SplittingExpression { get; } = new Regex(@"(\p{Lu}+(?=$|\p{Lu}[\p{Ll}0-9])|\p{Lu}?[\p{Ll}0-9]+)"); | ||
|
||
public string SeparatorCharacter => string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace AutoMapper | ||
{ | ||
/// <summary> | ||
/// Generic-friendly implementation of <see cref="ITypeConverter{TSource,TDestination}"/> | ||
/// </summary> | ||
/// <typeparam name="TSource">Source type</typeparam> | ||
/// <typeparam name="TDestination">Destination type</typeparam> | ||
public abstract class TypeConverter<TSource, TDestination> : ITypeConverter<TSource, TDestination> | ||
{ | ||
public TDestination Convert(ResolutionContext context) | ||
{ | ||
if (context.SourceValue != null && !(context.SourceValue is TSource)) | ||
{ | ||
throw new AutoMapperMappingException(context, | ||
$"Value supplied is of type {typeof (TSource)} but expected {context.SourceValue.GetType()}.\nChange the type converter source type, or redirect the source value supplied to the value resolver using FromMember."); | ||
} | ||
|
||
return ConvertCore((TSource)context.SourceValue); | ||
} | ||
|
||
/// <summary> | ||
/// When overridden in a base class, this method is provided the casted source object extracted from the <see cref="ResolutionContext"/> | ||
/// </summary> | ||
/// <param name="source">Source object</param> | ||
/// <returns>Destination object</returns> | ||
protected abstract TDestination ConvertCore(TSource source); | ||
} | ||
} |