Skip to content

Commit

Permalink
fix include code gen
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaowlert committed Aug 2, 2020
1 parent 7a73d50 commit 86d845c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
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 @@ public TypeAdapterSetter<TSource, TDestination> BeforeMappingInline(Expression<A
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 86d845c

Please sign in to comment.