-
-
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.
Merge pull request #2261 from jbogard/ValueTransformers
Value transformers in global, profiles, type maps, and members
- Loading branch information
Showing
15 changed files
with
376 additions
and
17 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
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
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
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
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,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq.Expressions; | ||
|
||
namespace AutoMapper | ||
{ | ||
public struct ValueTransformerConfiguration | ||
{ | ||
public ValueTransformerConfiguration(Type valueType, LambdaExpression transformerExpression) | ||
{ | ||
ValueType = valueType; | ||
TransformerExpression = transformerExpression; | ||
} | ||
|
||
public Type ValueType { get; } | ||
public LambdaExpression TransformerExpression { get; } | ||
|
||
public bool IsMatch(PropertyMap propertyMap) | ||
{ | ||
return propertyMap.DestinationPropertyType.IsAssignableFrom(ValueType); | ||
} | ||
} | ||
|
||
public static class ValueTransformerConfigurationExtensions | ||
{ | ||
/// <summary> | ||
/// Apply a transformation function after any resolved destination member value with the given type | ||
/// </summary> | ||
/// <typeparam name="TValue">Value type to match and transform</typeparam> | ||
/// <param name="valueTransformers">Value transformer list</param> | ||
/// <param name="transformer">Transformation expression</param> | ||
public static void Add<TValue>(this IList<ValueTransformerConfiguration> valueTransformers, | ||
Expression<Func<TValue, TValue>> transformer) | ||
{ | ||
var config = new ValueTransformerConfiguration(typeof(TValue), transformer); | ||
|
||
valueTransformers.Add(config); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.