Back to Mapster

Packages - Expression Debugging

docs/articles/packages/ExpressionDebugging.md

10.0.71.8 KB
Original Source

This Package allows you to perform step-into debugging using Roslyn!

nuget
    PM> Install-Package ExpressionDebugger

Usage

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

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

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

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

Using internal classes or members

private, protected and internal aren't allowed in debug mode.

Get mapping script

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

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

Specifics for Visual Studio on Mac

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

csharp
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 is actually faster than default dynamic compilation by 2x. Here is the result:

MethodMeanStdDevErrorGen 0Gen 1Gen 2Allocated
'Mapster 4.1.1'115.31 ms0.849 ms1.426 ms31000.0000--124.36 MB
'Mapster 4.1.1 (Roslyn)'53.55 ms0.342 ms0.654 ms31100.0000--124.36 MB