Skip to content

Commit fde27d6

Browse files
authored
chore: Merge pull request #861 from MapsterMapper/development
Merge Development to Master - Release v10.0.0
2 parents eba5cca + 753a02a commit fde27d6

File tree

58 files changed

+639
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+639
-276
lines changed

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Writing mapping methods is a machine job. Do not waste your time, let Mapster do
2626
|------|--------|-------------|
2727
| **Mapster.Tool** | [![Mapster.Tool](https://img.shields.io/nuget/v/Mapster.Tool.svg?label=Mapster.Tool&color=informational)](https://www.nuget.org/packages/Mapster.Tool/latest) | [![Mapster.Tool](https://img.shields.io/nuget/vpre/Mapster.Tool.svg?label=Mapster.Tool&color=orange)](https://www.nuget.org/packages/Mapster.Tool) |
2828

29-
_Badges zeigen die jeweils aktuellste Stable-Version und die aktuellste Pre-Release-Version._
3029

3130
## Installation
3231

@@ -105,7 +104,7 @@ using (MyDbContext context = new MyDbContext())
105104

106105
### Generating models & mappers
107106

108-
No need to write your own DTO classes. Mapster provides [Mapster.Tool](https://github.com/MapsterMapper/Mapster/wiki/Mapster.Tool) to help you generating models. And if you would like to have explicit mapping, Mapster also generates mapper class for you.
107+
No need to write your own DTO classes. Mapster provides [Mapster.Tool](https://mapstermapper.github.io/Mapster/articles/tools/mapster-tool/Mapster-Tool-Overview.html) to help you generating models. And if you would like to have explicit mapping, Mapster also generates mapper class for you.
109108

110109
```csharp
111110
[AdaptTo("[name]Dto"), GenerateMapper]
@@ -129,14 +128,14 @@ public static class StudentMapper {
129128

130129
## What's new
131130

132-
- [Fluent API for code generation](https://github.com/MapsterMapper/Mapster/wiki/Fluent-API-Code-generation)
133-
- [Automatically generate mapping code on build](https://github.com/MapsterMapper/Mapster/wiki/Mapster.Tool)
134-
- [Define setting to nested mapping](https://github.com/MapsterMapper/Mapster/wiki/Config-for-nested-mapping)
135-
- [`ISet`, `IDictionary`, `IReadOnlyDictionary` support](https://github.com/MapsterMapper/Mapster/wiki/Data-types#collections)
136-
- [`EmptyCollectionIfNull`, `CreateNewIfNull` DestinationTransform](https://github.com/MapsterMapper/Mapster/wiki/Setting-values#transform-value)
131+
- [Fluent API for code generation](https://mapstermapper.github.io/Mapster/articles/tools/mapster-tool/Fluent-API-Code-generation.html)
132+
- [Automatically generate mapping code on build](https://mapstermapper.github.io/Mapster/articles/tools/mapster-tool/Mapster-Tool-Overview.html)
133+
- [Define setting to nested mapping](https://mapstermapper.github.io/Mapster/articles/configuration/Config-for-nested-mapping.html)
134+
- [`ISet`, `IDictionary`, `IReadOnlyDictionary` support](https://mapstermapper.github.io/Mapster/articles/mapping/Data-types.html#collections)
135+
- [`EmptyCollectionIfNull`, `CreateNewIfNull` DestinationTransform](https://mapstermapper.github.io/Mapster/articles/settings/Setting-values.html#transform-value)
137136
- [Several fixes](https://github.com/MapsterMapper/Mapster/releases/)
138137
- New plugins
139-
- [Immutable collection support](https://github.com/MapsterMapper/Mapster/wiki/Immutable)
138+
- [Immutable collection support](https://mapstermapper.github.io/Mapster/articles/packages/Immutable.html)
140139
141140
## Why Mapster?
142141

@@ -145,8 +144,8 @@ public static class StudentMapper {
145144
Mapster was designed to be efficient on both speed and memory. You could gain a 4x performance improvement whilst using only 1/3 of memory.
146145
And you could gain up to 12x faster performance with:
147146

148-
- [Roslyn Compiler](https://github.com/MapsterMapper/Mapster/wiki/Debugging)
149-
- [FEC](https://github.com/MapsterMapper/Mapster/wiki/FastExpressionCompiler)
147+
- [Roslyn Compiler](https://mapstermapper.github.io/Mapster/articles/packages/ExpressionDebugging.html)
148+
- [FEC](https://mapstermapper.github.io/Mapster/articles/packages/FastExpressionCompiler.html)
150149
- Code generation
151150

152151
| Method | Mean | StdDev | Error | Gen 0 | Gen 1 | Gen 2 | Allocated |
@@ -175,8 +174,8 @@ Code generation allows you to
175174

176175
There are currently two tools which you can choose based on your preferences.
177176

178-
- [Mapster.Tool](https://github.com/MapsterMapper/Mapster/wiki/Mapster.Tool) _**NEW!**_
179-
- [TextTemplate](https://github.com/MapsterMapper/Mapster/wiki/TextTemplate)
177+
- [Mapster.Tool](https://mapstermapper.github.io/Mapster/articles/tools/mapster-tool/Mapster-Tool-Overview.html) _**NEW!**_
178+
- [TextTemplate](https://mapstermapper.github.io/Mapster/articles/tools/TextTemplate.html)
180179
181180
## Change logs
182181

docs/Clean-and-Build-Docs.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Write-Information "Cleaning obsolete API documentation..." -InformationAction Co
3030
# Step 3: Build documentation
3131
Write-Information "Building documentation..." -InformationAction Continue
3232

33-
& .\Build-Docs.ps1 -LogLevel $LogLevel -serve $true -open-browser $true
33+
& .\Build-Docs.ps1 -LogLevel $LogLevel -serve $true -openbrowser $true
3434

3535
if ($LASTEXITCODE -ne 0) {
3636
Write-Error "Documentation build failed"

docs/articles/mapping/Data-types.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,77 @@ var dict = point.Adapt<Dictionary<string, int>>();
9494
dict["Y"].ShouldBe(3);
9595
```
9696

97+
## Record types
98+
99+
>[!IMPORTANT]
100+
> Mapster treats Record type as an immutable type.
101+
> Only a Nondestructive mutation - creating a new object with modified properties.
102+
>
103+
> ```csharp
104+
> var result = source.adapt(data)
105+
>//equal var result = data with { X = source.X.Adapt(), ...}
106+
>```
107+
108+
### Features and Limitations:
109+
110+
# [v10.0](#tab/Records-v10)
111+
112+
>[!NOTE]
113+
> By default, all [C# Records](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record) are defined as a record type.
114+
> Limitations by count of constructors and constructor parameters used in Mapster version 7.4.0 do not apply.
115+
116+
117+
#### Using default value in constuctor param
118+
119+
If the source type does not contain members that can be used as constructor parameters, then will be used the default values ​​for the parameter type.
120+
121+
Example:
122+
123+
```csharp
124+
125+
class SourceData
126+
{
127+
public string MyString {get; set;}
128+
}
129+
130+
record RecordDestination(int myInt, string myString);
131+
132+
var result = source.Adapt<RecordDestination>()
133+
134+
// equal var result = new RecordDestination (default(int),source.myString)
135+
136+
```
137+
138+
#### MultyConsturctor Record types
139+
140+
If there is more than one constructor, by default, mapping will be performed on the constructor with the largest number of parameters.
141+
142+
Example:
143+
144+
```csharp
145+
record MultiCtorRecord
146+
{
147+
public MultiCtorRecord(int myInt)
148+
{
149+
MyInt = myInt;
150+
}
151+
152+
public MultiCtorRecord(int myInt, string myString) // This constructor will be used
153+
: this(myInt)
154+
{
155+
MyString = myString;
156+
}
157+
158+
}
159+
```
160+
161+
# [v7.4.0](#tab/Records-v7-4-0)
162+
163+
>[!NOTE]
164+
>Record type must not have a setter and have only one non-empty constructor, and all parameter names must match with properties.
165+
166+
Otherwise you need to add [`MapToConstructor` configuration](xref:Mapster.Settings.ConstructorMapping#map-to-constructor).
167+
97168
Example for record types:
98169
99170
```csharp
@@ -110,5 +181,12 @@ class Person {
110181
var src = new { Name = "Mapster", Age = 3 };
111182
var target = src.Adapt<Person>();
112183
```
184+
---
185+
186+
### Support additional mapping features:
113187
114-
There are limitations to map Record type automatically. Record type must not have a setter and have only one non-empty constructor, and all parameter names must match with properties. Otherwise you need to add [`MapToConstructor` configuration](xref:Mapster.Settings.ConstructorMapping#map-to-constructor).
188+
| Mapping features | v7.4.0 | v10.0 |
189+
|:-----------------|:------:|:-----:|
190+
|[Custom constructor mapping](xref:Mapster.Settings.ConstructorMapping)| - ||
191+
|[Ignore](xref:Mapster.Settings.Custom.IgnoringMembers#ignore-extension-method)| - ||
192+
|[IgnoreNullValues](xref:Mapster.Settings.Custom.IgnoringMembers#ignorenullvalues-extension-method)| - ||

src/Benchmark/Benchmark.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
</Compile>
2020
</ItemGroup>
2121
<ItemGroup>
22-
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
22+
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
2323
<PackageReference Include="ExpressionDebugger" Version="2.2.1" />
2424
<PackageReference Include="ExpressionTranslator" Version="2.5.0" />
25-
<PackageReference Include="AutoMapper" Version="13.0.1" />
26-
<PackageReference Include="FastExpressionCompiler" Version="5.0.0" />
25+
<PackageReference Include="FastExpressionCompiler" Version="5.3.0" />
2726
</ItemGroup>
2827
<ItemGroup>
2928
<ProjectReference Include="..\ExpressionDebugger\ExpressionDebugger.csproj" />

src/Benchmark/Benchmarks/TestAll.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,47 @@ public class TestAll
1111
[Params(100_000)]//, 1_000_000)]
1212
public int Iterations { get; set; }
1313

14-
[Benchmark(Description = "Mapster 7.2.0")]
14+
[Benchmark(Description = $"Mapster {TestAdaptHelper.MapsterVersion}")]
1515
public void MapsterTest()
1616
{
1717
TestAdaptHelper.TestMapsterAdapter<Foo, Foo>(_fooInstance, Iterations);
1818
TestAdaptHelper.TestMapsterAdapter<Customer, CustomerDTO>(_customerInstance, Iterations);
1919
}
2020

21-
[Benchmark(Description = "Mapster 7.2.0 (Roslyn)")]
21+
[Benchmark(Description = $"Mapster {TestAdaptHelper.MapsterVersion} (Roslyn)")]
2222
public void RoslynTest()
2323
{
2424
TestAdaptHelper.TestMapsterAdapter<Foo, Foo>(_fooInstance, Iterations);
2525
TestAdaptHelper.TestMapsterAdapter<Customer, CustomerDTO>(_customerInstance, Iterations);
2626
}
2727

28-
[Benchmark(Description = "Mapster 7.2.0 (FEC)")]
28+
[Benchmark(Description = $"Mapster {TestAdaptHelper.MapsterVersion} (FEC)")]
2929
public void FecTest()
3030
{
3131
TestAdaptHelper.TestMapsterAdapter<Foo, Foo>(_fooInstance, Iterations);
3232
TestAdaptHelper.TestMapsterAdapter<Customer, CustomerDTO>(_customerInstance, Iterations);
3333
}
3434

35-
[Benchmark(Description = "Mapster 7.2.0 (Codegen)")]
35+
[Benchmark(Description = $"Mapster {TestAdaptHelper.MapsterVersion} (Codegen)")]
3636
public void CodegenTest()
3737
{
3838
TestAdaptHelper.TestCodeGen(_fooInstance, Iterations);
3939
TestAdaptHelper.TestCodeGen(_customerInstance, Iterations);
4040
}
4141

42-
[Benchmark(Description = "ExpressMapper 1.9.1")]
42+
[Benchmark(Description = $"ExpressMapper {TestAdaptHelper.ExpressionMapperVersion}")]
4343
public void ExpressMapperTest()
4444
{
4545
TestAdaptHelper.TestExpressMapper<Foo, Foo>(_fooInstance, Iterations);
4646
TestAdaptHelper.TestExpressMapper<Customer, CustomerDTO>(_customerInstance, Iterations);
4747
}
4848

49-
[Benchmark(Description = "AutoMapper 10.1.1")]
50-
public void AutoMapperTest()
51-
{
52-
TestAdaptHelper.TestAutoMapper<Foo, Foo>(_fooInstance, Iterations);
53-
TestAdaptHelper.TestAutoMapper<Customer, CustomerDTO>(_customerInstance, Iterations);
54-
}
49+
//[Benchmark(Description = $"AutoMapper {TestAdaptHelper.AutoMapperVersion}")]
50+
//public void AutoMapperTest()
51+
//{
52+
// TestAdaptHelper.TestAutoMapper<Foo, Foo>(_fooInstance, Iterations);
53+
// TestAdaptHelper.TestAutoMapper<Customer, CustomerDTO>(_customerInstance, Iterations);
54+
//}
5555

5656
[GlobalSetup(Target = nameof(MapsterTest))]
5757
public void SetupMapster()
@@ -98,14 +98,14 @@ public void SetupExpressMapper()
9898
TestAdaptHelper.ConfigureExpressMapper(_customerInstance);
9999
}
100100

101-
[GlobalSetup(Target = nameof(AutoMapperTest))]
102-
public void SetupAutoMapper()
103-
{
104-
_fooInstance = TestAdaptHelper.SetupFooInstance();
105-
_customerInstance = TestAdaptHelper.SetupCustomerInstance();
106-
TestAdaptHelper.ConfigureAutoMapper(_fooInstance);
107-
TestAdaptHelper.ConfigureAutoMapper(_customerInstance);
108-
}
101+
//[GlobalSetup(Target = nameof(AutoMapperTest))]
102+
//public void SetupAutoMapper()
103+
//{
104+
// _fooInstance = TestAdaptHelper.SetupFooInstance();
105+
// _customerInstance = TestAdaptHelper.SetupCustomerInstance();
106+
// TestAdaptHelper.ConfigureAutoMapper(_fooInstance);
107+
// TestAdaptHelper.ConfigureAutoMapper(_customerInstance);
108+
//}
109109

110110
}
111111
}

src/Benchmark/Benchmarks/TestComplexTypes.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public void MapsterTest()
1616
TestAdaptHelper.TestMapsterAdapter<Customer, CustomerDTO>(_customerInstance, Iterations);
1717
}
1818

19-
[Benchmark(Description = "Mapster 6.0.0 (Roslyn)")]
19+
[Benchmark(Description = $"Mapster {TestAdaptHelper.MapsterVersion} (Roslyn)")]
2020
public void RoslynTest()
2121
{
2222
TestAdaptHelper.TestMapsterAdapter<Customer, CustomerDTO>(_customerInstance, Iterations);
2323
}
2424

25-
[Benchmark(Description = "Mapster 6.0.0 (FEC)")]
25+
[Benchmark(Description = $"Mapster {TestAdaptHelper.MapsterVersion} (FEC)")]
2626
public void FecTest()
2727
{
2828
TestAdaptHelper.TestMapsterAdapter<Customer, CustomerDTO>(_customerInstance, Iterations);
@@ -40,11 +40,11 @@ public void ExpressMapperTest()
4040
TestAdaptHelper.TestExpressMapper<Customer, CustomerDTO>(_customerInstance, Iterations);
4141
}
4242

43-
[Benchmark]
44-
public void AutoMapperTest()
45-
{
46-
TestAdaptHelper.TestAutoMapper<Customer, CustomerDTO>(_customerInstance, Iterations);
47-
}
43+
//[Benchmark]
44+
//public void AutoMapperTest()
45+
//{
46+
// TestAdaptHelper.TestAutoMapper<Customer, CustomerDTO>(_customerInstance, Iterations);
47+
//}
4848

4949
[GlobalSetup(Target = nameof(MapsterTest))]
5050
public void SetupMapster()
@@ -81,11 +81,11 @@ public void SetupExpressMapper()
8181
TestAdaptHelper.ConfigureExpressMapper(_customerInstance);
8282
}
8383

84-
[GlobalSetup(Target = nameof(AutoMapperTest))]
85-
public void SetupAutoMapper()
86-
{
87-
_customerInstance = TestAdaptHelper.SetupCustomerInstance();
88-
TestAdaptHelper.ConfigureAutoMapper(_customerInstance);
89-
}
84+
//[GlobalSetup(Target = nameof(AutoMapperTest))]
85+
//public void SetupAutoMapper()
86+
//{
87+
// _customerInstance = TestAdaptHelper.SetupCustomerInstance();
88+
// TestAdaptHelper.ConfigureAutoMapper(_customerInstance);
89+
//}
9090
}
9191
}

src/Benchmark/Benchmarks/TestSimpleTypes.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public void MapsterTest()
1616
TestAdaptHelper.TestMapsterAdapter<Foo, Foo>(_fooInstance, Iterations);
1717
}
1818

19-
[Benchmark(Description = "Mapster 6.0.0 (Roslyn)")]
19+
[Benchmark(Description = $"Mapster {TestAdaptHelper.MapsterVersion} (Roslyn)")]
2020
public void RoslynTest()
2121
{
2222
TestAdaptHelper.TestMapsterAdapter<Foo, Foo>(_fooInstance, Iterations);
2323
}
2424

25-
[Benchmark(Description = "Mapster 6.0.0 (FEC)")]
25+
[Benchmark(Description = $"Mapster {TestAdaptHelper.MapsterVersion} (FEC)")]
2626
public void FecTest()
2727
{
2828
TestAdaptHelper.TestMapsterAdapter<Foo, Foo>(_fooInstance, Iterations);
@@ -40,11 +40,11 @@ public void ExpressMapperTest()
4040
TestAdaptHelper.TestExpressMapper<Foo, Foo>(_fooInstance, Iterations);
4141
}
4242

43-
[Benchmark]
44-
public void AutoMapperTest()
45-
{
46-
TestAdaptHelper.TestAutoMapper<Foo, Foo>(_fooInstance, Iterations);
47-
}
43+
//[Benchmark]
44+
//public void AutoMapperTest()
45+
//{
46+
// TestAdaptHelper.TestAutoMapper<Foo, Foo>(_fooInstance, Iterations);
47+
//}
4848

4949

5050
[GlobalSetup(Target = nameof(MapsterTest))]
@@ -82,11 +82,11 @@ public void SetupExpressMapper()
8282
TestAdaptHelper.ConfigureExpressMapper(_fooInstance);
8383
}
8484

85-
[GlobalSetup(Target = nameof(AutoMapperTest))]
86-
public void SetupAutoMapper()
87-
{
88-
_fooInstance = TestAdaptHelper.SetupFooInstance();
89-
TestAdaptHelper.ConfigureAutoMapper(_fooInstance);
90-
}
85+
//[GlobalSetup(Target = nameof(AutoMapperTest))]
86+
//public void SetupAutoMapper()
87+
//{
88+
// _fooInstance = TestAdaptHelper.SetupFooInstance();
89+
// TestAdaptHelper.ConfigureAutoMapper(_fooInstance);
90+
//}
9191
}
9292
}

0 commit comments

Comments
 (0)