Skip to content

Commit f3ca0c5

Browse files
authored
Merge pull request #591 from MapsterMapper/development
Merge development to main pending new release
2 parents dc99b02 + 65c56cb commit f3ca0c5

File tree

46 files changed

+827
-249
lines changed

Some content is hidden

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

46 files changed

+827
-249
lines changed

src/ExpressionDebugger.Console/ExpressionDebugger.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
66
<UseNETCoreGenerator>true</UseNETCoreGenerator>
77
</PropertyGroup>
88

src/ExpressionDebugger.Tests/ExpressionDebugger.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

src/ExpressionDebugger/ExpressionDebugger.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
55
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
66
<Authors>Chaowlert Chaisrichalermpol</Authors>
77
<Description>Step into debugging from linq expressions</Description>

src/ExpressionTranslator/ExpressionTranslator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
55
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
66
<Authors>Chaowlert Chaisrichalermpol</Authors>
77
<Description>Translate from linq expressions to C# code</Description>

src/Mapster.Async.Tests/Mapster.Async.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

src/Mapster.Async/Mapster.Async.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
55
<Description>Async supports for Mapster</Description>
66
<IsPackable>true</IsPackable>
77
<PackageTags>Mapster;Async</PackageTags>
88
<SignAssembly>true</SignAssembly>
99
<AssemblyOriginatorKeyFile>Mapster.Async.snk</AssemblyOriginatorKeyFile>
10-
<Version>2.0.0</Version>
10+
<Version>2.0.1-pre02</Version>
1111
</PropertyGroup>
1212

1313
<ItemGroup>

src/Mapster.Async/TypeAdapterExtensions.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ internal static U GetValueOrDefault<T, U>(this IDictionary<T, U> dict, T key)
1313
return dict.TryGetValue(key, out var value) ? value : default;
1414
}
1515

16-
public static TypeAdapterSetter<TDestination> AfterMappingAsync<TDestination>(
16+
17+
/// <summary>
18+
/// Setup async operation
19+
/// </summary>
20+
/// <typeparam name="TDestination"></typeparam>
21+
/// <param name="setter"></param>
22+
/// <param name="action"></param>
23+
/// <returns></returns>
24+
/// <exception cref="InvalidOperationException"></exception>
25+
public static TypeAdapterSetter<TDestination> AfterMappingAsync<TDestination>(
1726
this TypeAdapterSetter<TDestination> setter, Func<TDestination, Task> action)
1827
{
1928
setter.AfterMapping(dest =>
@@ -27,7 +36,17 @@ public static TypeAdapterSetter<TDestination> AfterMappingAsync<TDestination>(
2736
return setter;
2837
}
2938

30-
public static TypeAdapterSetter<TSource, TDestination> AfterMappingAsync<TSource, TDestination>(
39+
40+
/// <summary>
41+
/// Setup async operation
42+
/// </summary>
43+
/// <typeparam name="TSource"></typeparam>
44+
/// <typeparam name="TDestination"></typeparam>
45+
/// <param name="setter"></param>
46+
/// <param name="action"></param>
47+
/// <returns></returns>
48+
/// <exception cref="InvalidOperationException"></exception>
49+
public static TypeAdapterSetter<TSource, TDestination> AfterMappingAsync<TSource, TDestination>(
3150
this TypeAdapterSetter<TSource, TDestination> setter, Func<TSource, TDestination, Task> action)
3251
{
3352
setter.AfterMapping((src, dest) =>
@@ -41,7 +60,14 @@ public static TypeAdapterSetter<TSource, TDestination> AfterMappingAsync<TSource
4160
return setter;
4261
}
4362

44-
public static async Task<TDestination> AdaptToTypeAsync<TDestination>(this IAdapterBuilder builder)
63+
64+
/// <summary>
65+
/// Map asynchronously to destination type.
66+
/// </summary>
67+
/// <typeparam name="TDestination">Destination type to map.</typeparam>
68+
/// <param name="builder"></param>
69+
/// <returns>Type of destination object that mapped.</returns>
70+
public static async Task<TDestination> AdaptToTypeAsync<TDestination>(this IAdapterBuilder builder)
4571
{
4672
var tasks = new List<Task>();
4773
builder.Parameters[ASYNC_KEY] = tasks;
@@ -54,7 +80,15 @@ public static async Task<TDestination> AdaptToTypeAsync<TDestination>(this IAdap
5480
}
5581
}
5682

57-
public static async Task<TDestination> AdaptToAsync<TDestination>(this IAdapterBuilder builder, TDestination destination)
83+
84+
/// <summary>
85+
/// Map asynchronously to destination type.
86+
/// </summary>
87+
/// <typeparam name="TDestination">Destination type to map.</typeparam>
88+
/// <param name="builder"></param>
89+
/// <param name="destination">Destination object to map.</param>
90+
/// <returns>Type of destination object that mapped.</returns>
91+
public static async Task<TDestination> AdaptToAsync<TDestination>(this IAdapterBuilder builder, TDestination destination)
5892
{
5993
var tasks = new List<Task>();
6094
builder.Parameters[ASYNC_KEY] = tasks;

src/Mapster.Core/MapContext/MapContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Threading;
5-
65
namespace Mapster
76
{
87
/// <summary>
@@ -15,7 +14,7 @@ namespace Mapster
1514
/// </remarks>
1615
public class MapContext
1716
{
18-
#if NETSTANDARD || NET6_0_OR_GREATER
17+
#if (NETSTANDARD || NET6_0_OR_GREATER) && !MAPSTER_FORCE_LEGACY_MAPCONTEXT
1918
private static readonly AsyncLocal<MapContext?> _localContext = new AsyncLocal<MapContext?>();
2019
public static MapContext? Current
2120
{

src/Mapster.Core/Mapster.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Description>Lightweight library for Mapster and Mapster CodeGen</Description>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
55
<AssemblyName>Mapster.Core</AssemblyName>
66
<PackageTags>mapster</PackageTags>
7-
<Version>1.2.1-pre02</Version>
7+
<Version>1.2.1-pre04</Version>
88
<Nullable>enable</Nullable>
99
<IsPackable>true</IsPackable>
1010
<SignAssembly>true</SignAssembly>

src/Mapster.Core/Register/AdaptAttributeBuilder.cs

Lines changed: 117 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ public AdaptAttributeBuilder(BaseAdaptAttribute attribute)
1616
this.Attribute = attribute;
1717
}
1818

19-
public AdaptAttributeBuilder ForTypes(params Type[] types)
19+
/// <summary>
20+
/// Configures the builder for specific types.
21+
/// </summary>
22+
/// <param name="types">Types to configure.</param>
23+
/// <returns></returns>
24+
public AdaptAttributeBuilder ForTypes(params Type[] types)
2025
{
2126
foreach (var type in types)
2227
{
@@ -27,7 +32,14 @@ public AdaptAttributeBuilder ForTypes(params Type[] types)
2732
return this;
2833
}
2934

30-
public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @namespace)
35+
36+
/// <summary>
37+
/// Configures the builder for all types in a given namespace within an assembly.
38+
/// </summary>
39+
/// <param name="assembly">The assembly containing the types.</param>
40+
/// <param name="namespace">The namespace of the types to include.</param>
41+
/// <returns></returns>
42+
public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @namespace)
3143
{
3244
foreach (var type in assembly.GetTypes())
3345
{
@@ -40,7 +52,14 @@ public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @n
4052
return this;
4153
}
4254

43-
public AdaptAttributeBuilder ForType<T>(Action<PropertySettingBuilder<T>>? propertyConfig = null)
55+
56+
/// <summary>
57+
/// Configures the builder for a specific type and allows for property-specific configuration.
58+
/// </summary>
59+
/// <typeparam name="T"></typeparam>
60+
/// <param name="propertyConfig">An optional action for configuring properties of the specified type.</param>
61+
/// <returns></returns>
62+
public AdaptAttributeBuilder ForType<T>(Action<PropertySettingBuilder<T>>? propertyConfig = null)
4463
{
4564
if (!this.TypeSettings.TryGetValue(typeof(T), out var settings))
4665
{
@@ -52,7 +71,13 @@ public AdaptAttributeBuilder ForType<T>(Action<PropertySettingBuilder<T>>? prope
5271
return this;
5372
}
5473

55-
public AdaptAttributeBuilder ExcludeTypes(params Type[] types)
74+
75+
/// <summary>
76+
/// Excludes specific types from the configuration.
77+
/// </summary>
78+
/// <param name="types">An array of types to exclude.</param>
79+
/// <returns></returns>
80+
public AdaptAttributeBuilder ExcludeTypes(params Type[] types)
5681
{
5782
foreach (var type in types)
5883
{
@@ -62,7 +87,13 @@ public AdaptAttributeBuilder ExcludeTypes(params Type[] types)
6287
return this;
6388
}
6489

65-
public AdaptAttributeBuilder ExcludeTypes(Func<Type, bool> predicate)
90+
91+
/// <summary>
92+
/// Exclude certain types from the adaptation process based on a provided predicate.
93+
/// </summary>
94+
/// <param name="predicate">Predicate function should evaluate to true for types that you want to exclude from the mapping and false for types that should not be excluded.</param>
95+
/// <returns></returns>
96+
public AdaptAttributeBuilder ExcludeTypes(Func<Type, bool> predicate)
6697
{
6798
foreach (var type in this.TypeSettings.Keys.ToList())
6899
{
@@ -73,67 +104,135 @@ public AdaptAttributeBuilder ExcludeTypes(Func<Type, bool> predicate)
73104
return this;
74105
}
75106

76-
public AdaptAttributeBuilder IgnoreAttributes(params Type[] attributes)
107+
108+
/// <summary>
109+
/// Specifies attributes to ignore during mapping.
110+
/// </summary>
111+
/// <param name="attributes">An array of attributes to ignore.</param>
112+
/// <returns></returns>
113+
public AdaptAttributeBuilder IgnoreAttributes(params Type[] attributes)
77114
{
78115
this.Attribute.IgnoreAttributes = attributes;
79116
return this;
80117
}
81118

82-
public AdaptAttributeBuilder IgnoreNoAttributes(params Type[] attributes)
119+
120+
/// <summary>
121+
/// Specifies attributes that should not be ignored during mapping.
122+
/// </summary>
123+
/// <param name="attributes">An array of attributes that should not be ignored.</param>
124+
/// <returns></returns>
125+
public AdaptAttributeBuilder IgnoreNoAttributes(params Type[] attributes)
83126
{
84127
this.Attribute.IgnoreNoAttributes = attributes;
85128
return this;
86129
}
87130

88-
public AdaptAttributeBuilder IgnoreNamespaces(params string[] namespaces)
131+
132+
/// <summary>
133+
/// Specifies namespaces to ignore during mapping.
134+
/// </summary>
135+
/// <param name="namespaces">An array of namespaces to ignore.</param>
136+
/// <returns></returns>
137+
public AdaptAttributeBuilder IgnoreNamespaces(params string[] namespaces)
89138
{
90139
this.Attribute.IgnoreNamespaces = namespaces;
91140
return this;
92141
}
93142

94-
public AdaptAttributeBuilder IgnoreNullValues(bool value)
143+
144+
/// <summary>
145+
/// Configures whether null values should be ignored during mapping.
146+
/// </summary>
147+
/// <param name="value">A boolean value indicating whether to ignore null values.</param>
148+
/// <returns></returns>
149+
public AdaptAttributeBuilder IgnoreNullValues(bool value)
95150
{
96151
this.Attribute.IgnoreNullValues = value;
97152
return this;
98153
}
99154

100-
public AdaptAttributeBuilder RequireDestinationMemberSource(bool value)
155+
156+
/// <summary>
157+
/// Configures whether a destination member source is required during.
158+
/// </summary>
159+
/// <param name="value">A boolean value indicating whether a destination member source is required.</param>
160+
/// <returns></returns>
161+
public AdaptAttributeBuilder RequireDestinationMemberSource(bool value)
101162
{
102163
this.Attribute.RequireDestinationMemberSource = value;
103164
return this;
104165
}
105166

106-
public AdaptAttributeBuilder MapToConstructor(bool value)
167+
168+
/// <summary>
169+
/// Configures whether mapping should be performed to constructors.
170+
/// </summary>
171+
/// <param name="value">A boolean value indicating whether mapping to constructors is enabled.</param>
172+
/// <returns></returns>
173+
public AdaptAttributeBuilder MapToConstructor(bool value)
107174
{
108175
this.Attribute.MapToConstructor = value;
109176
return this;
110177
}
111178

112-
public AdaptAttributeBuilder MaxDepth(int depth)
179+
180+
/// <summary>
181+
/// Sets the maximum depth for mapping.
182+
/// </summary>
183+
/// <param name="depth">The maximum depth for mapping.</param>
184+
/// <returns></returns>
185+
public AdaptAttributeBuilder MaxDepth(int depth)
113186
{
114187
this.Attribute.MaxDepth = depth;
115188
return this;
116189
}
117-
118-
public AdaptAttributeBuilder PreserveReference(bool value)
190+
191+
192+
/// <summary>
193+
/// Configures whether to preserve object references during mapping.
194+
/// </summary>
195+
/// <param name="value">A boolean value indicating whether to preserve object references.</param>
196+
/// <returns></returns>
197+
public AdaptAttributeBuilder PreserveReference(bool value)
119198
{
120199
this.Attribute.PreserveReference = value;
121200
return this;
122201
}
123-
124-
public AdaptAttributeBuilder ShallowCopyForSameType(bool value)
202+
203+
204+
/// <summary>
205+
/// Configures whether to perform a shallow copy for the same source and destination type.
206+
/// </summary>
207+
/// <param name="value">A boolean value indicating whether to perform a shallow copy.</param>
208+
/// <returns></returns>
209+
public AdaptAttributeBuilder ShallowCopyForSameType(bool value)
125210
{
126211
this.Attribute.ShallowCopyForSameType = value;
127212
return this;
128213
}
129214

130-
public AdaptAttributeBuilder AlterType<TFrom, TTo>()
215+
216+
/// <summary>
217+
/// Forward property types.
218+
/// </summary>
219+
/// <typeparam name="TFrom">Forward property from type.</typeparam>
220+
/// <typeparam name="TTo">Forward property to type.</typeparam>
221+
/// <returns></returns>
222+
public AdaptAttributeBuilder AlterType<TFrom, TTo>()
131223
{
132224
this.AlterTypes.Add(type => type == typeof(TFrom) ? typeof(TTo) : null);
133225
return this;
134226
}
135227

136-
public AdaptAttributeBuilder AlterType(Func<Type, bool> predicate, Type toType)
228+
229+
/// <summary>
230+
/// Forward property types for Code generation.
231+
/// </summary>
232+
/// <param name="predicate">A function that takes a Type as input and returns a Boolean value. This function is used to evaluate whether the forward property should be applied to the target type. If the predicate returns true, the target type will be replaced; otherwise, it remains unchanged.</param>
233+
/// <param name="toType">Type of destination to forward property type.</param>
234+
/// <returns></returns>
235+
public AdaptAttributeBuilder AlterType(Func<Type, bool> predicate, Type toType)
137236
{
138237
this.AlterTypes.Add(type => predicate(type) ? toType : null);
139238
return this;

0 commit comments

Comments
 (0)