Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chaowlert committed Aug 5, 2020
2 parents d6e70e8 + 86d845c commit de214c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Code generation lets you do mapping with
- Finding usage of your models' properties

There are 2 tools, you can choose based on your preference.
* [Mapster.Tool](https://github.com/MapsterMapper/Mapster/wiki/Mapster.Tool)
* [Mapster.Tool](https://github.com/MapsterMapper/Mapster/wiki/Mapster.Tool) NEW!
* [TextTemplate](https://github.com/MapsterMapper/Mapster/wiki/TextTemplate)

### Change logs
Expand Down
4 changes: 4 additions & 0 deletions src/Mapster.Tests/Mapster.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<ItemGroup>
<ProjectReference Include="..\Mapster\Mapster.csproj" />
</ItemGroup>
<Target Name="mapster" AfterTargets="AfterBuild">
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster -a $(TargetDir)$(ProjectName).dll" />
</Target>
<ItemGroup>
<None Remove="packages.config" />
<None Remove="mock.keys" />
Expand Down
6 changes: 5 additions & 1 deletion src/Mapster/Adapters/BaseAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ protected Expression CreateBlockExpressionBody(Expression source, Expression? de
set = Expression.Coalesce(destination, set);
}

if (set.NodeType != ExpressionType.Throw)
if (set.NodeType == ExpressionType.Throw)
{
blocks.Add(set);
}
else
{
//TDestination result;
//if (source == null)
Expand Down
20 changes: 18 additions & 2 deletions src/Mapster/TypeAdapterSetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,17 @@ public TypeAdapterSetter<TDestination> MapToConstructor(ConstructorInfo ctor)
this.Settings.MapToConstructor = ctor;
return this;
}

public TypeAdapterSetter<TDestination> AfterMappingInline(Expression<Action<TDestination>> action)
{
this.CheckCompiled();

var lambda = Expression.Lambda(action.Body,
Expression.Parameter(typeof(object), "src"),
action.Parameters[0]);
Settings.AfterMappingFactories.Add(arg => lambda);
return this;
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S4136:Method overloads should be grouped together", Justification = "<Pending>")]
Expand Down Expand Up @@ -416,6 +427,11 @@ internal TypeAdapterSetter(TypeAdapterSettings settings, TypeAdapterConfig paren
return (TypeAdapterSetter<TSource, TDestination>) base.MapToConstructor(ctor);
}

public new TypeAdapterSetter<TSource, TDestination> AfterMappingInline(Expression<Action<TDestination>> action)
{
return (TypeAdapterSetter<TSource, TDestination>) base.AfterMappingInline(action);
}

#endregion

public TypeAdapterSetter<TSource, TDestination> IgnoreIf(
Expand Down Expand Up @@ -570,15 +586,15 @@ internal TypeAdapterSetter(TypeAdapterSettings settings, TypeAdapterConfig paren
Settings.BeforeMappingFactories.Add(arg => action);
return this;
}

public TypeAdapterSetter<TSource, TDestination> AfterMappingInline(Expression<Action<TSource, TDestination>> action)
{
this.CheckCompiled();

Settings.AfterMappingFactories.Add(arg => action);
return this;
}

public TypeAdapterSetter<TSource, TDestination> Include<TDerivedSource, TDerivedDestination>()
where TDerivedSource: class, TSource
where TDerivedDestination: class, TDestination
Expand Down

0 comments on commit de214c7

Please sign in to comment.