Skip to content

Commit de214c7

Browse files
committed
2 parents d6e70e8 + 86d845c commit de214c7

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Code generation lets you do mapping with
8686
- Finding usage of your models' properties
8787

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

9292
### Change logs

src/Mapster.Tests/Mapster.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<ItemGroup>
2121
<ProjectReference Include="..\Mapster\Mapster.csproj" />
2222
</ItemGroup>
23+
<Target Name="mapster" AfterTargets="AfterBuild">
24+
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
25+
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster -a $(TargetDir)$(ProjectName).dll" />
26+
</Target>
2327
<ItemGroup>
2428
<None Remove="packages.config" />
2529
<None Remove="mock.keys" />

src/Mapster/Adapters/BaseAdapter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ protected Expression CreateBlockExpressionBody(Expression source, Expression? de
188188
set = Expression.Coalesce(destination, set);
189189
}
190190

191-
if (set.NodeType != ExpressionType.Throw)
191+
if (set.NodeType == ExpressionType.Throw)
192+
{
193+
blocks.Add(set);
194+
}
195+
else
192196
{
193197
//TDestination result;
194198
//if (source == null)

src/Mapster/TypeAdapterSetter.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ public TypeAdapterSetter<TDestination> MapToConstructor(ConstructorInfo ctor)
366366
this.Settings.MapToConstructor = ctor;
367367
return this;
368368
}
369+
370+
public TypeAdapterSetter<TDestination> AfterMappingInline(Expression<Action<TDestination>> action)
371+
{
372+
this.CheckCompiled();
373+
374+
var lambda = Expression.Lambda(action.Body,
375+
Expression.Parameter(typeof(object), "src"),
376+
action.Parameters[0]);
377+
Settings.AfterMappingFactories.Add(arg => lambda);
378+
return this;
379+
}
369380
}
370381

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

430+
public new TypeAdapterSetter<TSource, TDestination> AfterMappingInline(Expression<Action<TDestination>> action)
431+
{
432+
return (TypeAdapterSetter<TSource, TDestination>) base.AfterMappingInline(action);
433+
}
434+
419435
#endregion
420436

421437
public TypeAdapterSetter<TSource, TDestination> IgnoreIf(
@@ -570,15 +586,15 @@ public TypeAdapterSetter<TSource, TDestination> BeforeMappingInline(Expression<A
570586
Settings.BeforeMappingFactories.Add(arg => action);
571587
return this;
572588
}
573-
589+
574590
public TypeAdapterSetter<TSource, TDestination> AfterMappingInline(Expression<Action<TSource, TDestination>> action)
575591
{
576592
this.CheckCompiled();
577593

578594
Settings.AfterMappingFactories.Add(arg => action);
579595
return this;
580596
}
581-
597+
582598
public TypeAdapterSetter<TSource, TDestination> Include<TDerivedSource, TDerivedDestination>()
583599
where TDerivedSource: class, TSource
584600
where TDerivedDestination: class, TDestination

0 commit comments

Comments
 (0)