Skip to content
chaowlert edited this page Jan 21, 2020 · 13 revisions

Step-into debugging

PM> Install-Package ExpressionDebugger

This plugin allow you to perform step-into debugging using Roslyn!

Usage

Then add following code on start up (or anywhere before mapping is compiled)

TypeAdapterConfig.GlobalSettings.Compiler = exp => exp.CompileWithDebugInfo();

Now on your mapping code (only in DEBUG mode).

var dto = poco.Adapt<SimplePoco, SimpleDto>(); //<--- you can step-into this function!!

image

Using internal classes or members

private, protected and internal don't allow in debug mode.

Get mapping script

We can also see how Mapster generate mapping logic with ToScript method.

var script = poco.BuildAdapter()
                .CreateMapExpression<SimpleDto>()
                .ToScript();

Visual Studio for Mac

To step-into debugging, you might need to emit file

var opt = new ExpressionCompilationOptions { EmitFile = true };
TypeAdapterConfig.GlobalSettings.Compiler = exp => exp.CompileWithDebugInfo(opt);
...
var dto = poco.Adapt<SimplePoco, SimpleDto>(); //<-- you can step-into this function!!

Do not worry about performance

In RELEASE mode, Roslyn compiler actually faster than default dynamic compilation by 2x. Here is the result.

Method Mean StdDev Error Gen 0 Gen 1 Gen 2 Allocated
'Mapster 4.1.1' 115.31 ms 0.849 ms 1.426 ms 31000.0000 - - 124.36 MB
'Mapster 4.1.1 (Roslyn)' 53.55 ms 0.342 ms 0.654 ms 31100.0000 - - 124.36 MB

Clone this wiki locally