Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge development to main pending new release #591

Merged
merged 27 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e53f846
Refactor IMapper.From to return interface
gritcsenko Jul 18, 2022
0489cf7
Remove unnecessary edits
gritcsenko Jul 18, 2022
0a7e5cf
Merge remote-tracking branch 'upstream/master'
andrerav Sep 6, 2022
4486ab1
Fixed build errors
andrerav Sep 6, 2022
16d81ab
Merge pull request #454 from gritcsenko/master
andrerav Sep 7, 2022
e407f6e
Add .net 7.0 TFM to all projects (except benchmark) whilst maintainin…
pippipmilk Nov 14, 2022
d4697a8
Merge branch 'master' into development
andrerav Jan 3, 2023
6f858ec
Merge pull request #496 from cedwards-telis/development
andrerav Jan 3, 2023
56611d5
Bump package version numbers and update Pack.bat
andrerav Jan 3, 2023
8fd93d2
Merge latest from main
andrerav Jan 7, 2023
7f49243
Bump version numbers
andrerav Jan 7, 2023
84cd347
Added preprocessing flag that forces MapContext.Current to use Thread…
andrerav Feb 7, 2023
d154ced
Added regression test to test that mapping to an existing struct work…
andrerav Feb 7, 2023
3a4ee19
Added regression test that test mapping records with parameters
andrerav Feb 7, 2023
08621ce
Added regression test for testing mapping from a secondary source obj…
andrerav Feb 7, 2023
079ac4a
Merge branch 'master' into development
andrerav Feb 7, 2023
48cac1a
Mapster.Tool catch ReflectionTypeLoadException
EniacMlezi Feb 14, 2023
91f7793
Merge pull request #544 from EniacMlezi/development
andrerav Feb 21, 2023
2112369
Merge pull request #549 from MapsterMapper/master
andrerav Feb 21, 2023
1dbaa86
Merge pull request #553 from MapsterMapper/master
andrerav Feb 26, 2023
48745ed
Fix warning message
andrerav Feb 26, 2023
068c174
Update version numbers
andrerav Feb 26, 2023
c5ad6e6
Merge pull request #558 from MapsterMapper/master
andrerav Mar 4, 2023
31bc530
Merge latest from main
andrerav May 29, 2023
1e1d1f9
Methods Documention
HoseinHabibiyan Sep 3, 2023
9416447
Merge pull request #626 from HoseinHabibiyan/method-documention
andrerav Sep 21, 2023
65c56cb
Merge latest changes from master into development
andrerav Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/ExpressionDebugger/ExpressionDebugger.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Chaowlert Chaisrichalermpol</Authors>
<Description>Step into debugging from linq expressions</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/ExpressionTranslator/ExpressionTranslator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Chaowlert Chaisrichalermpol</Authors>
<Description>Translate from linq expressions to C# code</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Mapster.Async.Tests/Mapster.Async.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Mapster.Async/Mapster.Async.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<Description>Async supports for Mapster</Description>
<IsPackable>true</IsPackable>
<PackageTags>Mapster;Async</PackageTags>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Mapster.Async.snk</AssemblyOriginatorKeyFile>
<Version>2.0.0</Version>
<Version>2.0.1-pre02</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
42 changes: 38 additions & 4 deletions src/Mapster.Async/TypeAdapterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ internal static U GetValueOrDefault<T, U>(this IDictionary<T, U> dict, T key)
return dict.TryGetValue(key, out var value) ? value : default;
}

public static TypeAdapterSetter<TDestination> AfterMappingAsync<TDestination>(

/// <summary>
/// Setup async operation
/// </summary>
/// <typeparam name="TDestination"></typeparam>
/// <param name="setter"></param>
/// <param name="action"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static TypeAdapterSetter<TDestination> AfterMappingAsync<TDestination>(
this TypeAdapterSetter<TDestination> setter, Func<TDestination, Task> action)
{
setter.AfterMapping(dest =>
Expand All @@ -27,7 +36,17 @@ public static TypeAdapterSetter<TDestination> AfterMappingAsync<TDestination>(
return setter;
}

public static TypeAdapterSetter<TSource, TDestination> AfterMappingAsync<TSource, TDestination>(

/// <summary>
/// Setup async operation
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <typeparam name="TDestination"></typeparam>
/// <param name="setter"></param>
/// <param name="action"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public static TypeAdapterSetter<TSource, TDestination> AfterMappingAsync<TSource, TDestination>(
this TypeAdapterSetter<TSource, TDestination> setter, Func<TSource, TDestination, Task> action)
{
setter.AfterMapping((src, dest) =>
Expand All @@ -41,7 +60,14 @@ public static TypeAdapterSetter<TSource, TDestination> AfterMappingAsync<TSource
return setter;
}

public static async Task<TDestination> AdaptToTypeAsync<TDestination>(this IAdapterBuilder builder)

/// <summary>
/// Map asynchronously to destination type.
/// </summary>
/// <typeparam name="TDestination">Destination type to map.</typeparam>
/// <param name="builder"></param>
/// <returns>Type of destination object that mapped.</returns>
public static async Task<TDestination> AdaptToTypeAsync<TDestination>(this IAdapterBuilder builder)
{
var tasks = new List<Task>();
builder.Parameters[ASYNC_KEY] = tasks;
Expand All @@ -54,7 +80,15 @@ public static async Task<TDestination> AdaptToTypeAsync<TDestination>(this IAdap
}
}

public static async Task<TDestination> AdaptToAsync<TDestination>(this IAdapterBuilder builder, TDestination destination)

/// <summary>
/// Map asynchronously to destination type.
/// </summary>
/// <typeparam name="TDestination">Destination type to map.</typeparam>
/// <param name="builder"></param>
/// <param name="destination">Destination object to map.</param>
/// <returns>Type of destination object that mapped.</returns>
public static async Task<TDestination> AdaptToAsync<TDestination>(this IAdapterBuilder builder, TDestination destination)
{
var tasks = new List<Task>();
builder.Parameters[ASYNC_KEY] = tasks;
Expand Down
3 changes: 1 addition & 2 deletions src/Mapster.Core/MapContext/MapContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Threading;

namespace Mapster
{
/// <summary>
Expand All @@ -15,7 +14,7 @@ namespace Mapster
/// </remarks>
public class MapContext
{
#if NETSTANDARD || NET6_0_OR_GREATER
#if (NETSTANDARD || NET6_0_OR_GREATER) && !MAPSTER_FORCE_LEGACY_MAPCONTEXT
private static readonly AsyncLocal<MapContext?> _localContext = new AsyncLocal<MapContext?>();
public static MapContext? Current
{
Expand Down
4 changes: 2 additions & 2 deletions src/Mapster.Core/Mapster.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Lightweight library for Mapster and Mapster CodeGen</Description>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<AssemblyName>Mapster.Core</AssemblyName>
<PackageTags>mapster</PackageTags>
<Version>1.2.1-pre02</Version>
<Version>1.2.1-pre04</Version>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<SignAssembly>true</SignAssembly>
Expand Down
135 changes: 117 additions & 18 deletions src/Mapster.Core/Register/AdaptAttributeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ public AdaptAttributeBuilder(BaseAdaptAttribute attribute)
this.Attribute = attribute;
}

public AdaptAttributeBuilder ForTypes(params Type[] types)
/// <summary>
/// Configures the builder for specific types.
/// </summary>
/// <param name="types">Types to configure.</param>
/// <returns></returns>
public AdaptAttributeBuilder ForTypes(params Type[] types)
{
foreach (var type in types)
{
Expand All @@ -27,7 +32,14 @@ public AdaptAttributeBuilder ForTypes(params Type[] types)
return this;
}

public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @namespace)

/// <summary>
/// Configures the builder for all types in a given namespace within an assembly.
/// </summary>
/// <param name="assembly">The assembly containing the types.</param>
/// <param name="namespace">The namespace of the types to include.</param>
/// <returns></returns>
public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @namespace)
{
foreach (var type in assembly.GetTypes())
{
Expand All @@ -40,7 +52,14 @@ public AdaptAttributeBuilder ForAllTypesInNamespace(Assembly assembly, string @n
return this;
}

public AdaptAttributeBuilder ForType<T>(Action<PropertySettingBuilder<T>>? propertyConfig = null)

/// <summary>
/// Configures the builder for a specific type and allows for property-specific configuration.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="propertyConfig">An optional action for configuring properties of the specified type.</param>
/// <returns></returns>
public AdaptAttributeBuilder ForType<T>(Action<PropertySettingBuilder<T>>? propertyConfig = null)
{
if (!this.TypeSettings.TryGetValue(typeof(T), out var settings))
{
Expand All @@ -52,7 +71,13 @@ public AdaptAttributeBuilder ForType<T>(Action<PropertySettingBuilder<T>>? prope
return this;
}

public AdaptAttributeBuilder ExcludeTypes(params Type[] types)

/// <summary>
/// Excludes specific types from the configuration.
/// </summary>
/// <param name="types">An array of types to exclude.</param>
/// <returns></returns>
public AdaptAttributeBuilder ExcludeTypes(params Type[] types)
{
foreach (var type in types)
{
Expand All @@ -62,7 +87,13 @@ public AdaptAttributeBuilder ExcludeTypes(params Type[] types)
return this;
}

public AdaptAttributeBuilder ExcludeTypes(Func<Type, bool> predicate)

/// <summary>
/// Exclude certain types from the adaptation process based on a provided predicate.
/// </summary>
/// <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>
/// <returns></returns>
public AdaptAttributeBuilder ExcludeTypes(Func<Type, bool> predicate)
{
foreach (var type in this.TypeSettings.Keys.ToList())
{
Expand All @@ -73,67 +104,135 @@ public AdaptAttributeBuilder ExcludeTypes(Func<Type, bool> predicate)
return this;
}

public AdaptAttributeBuilder IgnoreAttributes(params Type[] attributes)

/// <summary>
/// Specifies attributes to ignore during mapping.
/// </summary>
/// <param name="attributes">An array of attributes to ignore.</param>
/// <returns></returns>
public AdaptAttributeBuilder IgnoreAttributes(params Type[] attributes)
{
this.Attribute.IgnoreAttributes = attributes;
return this;
}

public AdaptAttributeBuilder IgnoreNoAttributes(params Type[] attributes)

/// <summary>
/// Specifies attributes that should not be ignored during mapping.
/// </summary>
/// <param name="attributes">An array of attributes that should not be ignored.</param>
/// <returns></returns>
public AdaptAttributeBuilder IgnoreNoAttributes(params Type[] attributes)
{
this.Attribute.IgnoreNoAttributes = attributes;
return this;
}

public AdaptAttributeBuilder IgnoreNamespaces(params string[] namespaces)

/// <summary>
/// Specifies namespaces to ignore during mapping.
/// </summary>
/// <param name="namespaces">An array of namespaces to ignore.</param>
/// <returns></returns>
public AdaptAttributeBuilder IgnoreNamespaces(params string[] namespaces)
{
this.Attribute.IgnoreNamespaces = namespaces;
return this;
}

public AdaptAttributeBuilder IgnoreNullValues(bool value)

/// <summary>
/// Configures whether null values should be ignored during mapping.
/// </summary>
/// <param name="value">A boolean value indicating whether to ignore null values.</param>
/// <returns></returns>
public AdaptAttributeBuilder IgnoreNullValues(bool value)
{
this.Attribute.IgnoreNullValues = value;
return this;
}

public AdaptAttributeBuilder RequireDestinationMemberSource(bool value)

/// <summary>
/// Configures whether a destination member source is required during.
/// </summary>
/// <param name="value">A boolean value indicating whether a destination member source is required.</param>
/// <returns></returns>
public AdaptAttributeBuilder RequireDestinationMemberSource(bool value)
{
this.Attribute.RequireDestinationMemberSource = value;
return this;
}

public AdaptAttributeBuilder MapToConstructor(bool value)

/// <summary>
/// Configures whether mapping should be performed to constructors.
/// </summary>
/// <param name="value">A boolean value indicating whether mapping to constructors is enabled.</param>
/// <returns></returns>
public AdaptAttributeBuilder MapToConstructor(bool value)
{
this.Attribute.MapToConstructor = value;
return this;
}

public AdaptAttributeBuilder MaxDepth(int depth)

/// <summary>
/// Sets the maximum depth for mapping.
/// </summary>
/// <param name="depth">The maximum depth for mapping.</param>
/// <returns></returns>
public AdaptAttributeBuilder MaxDepth(int depth)
{
this.Attribute.MaxDepth = depth;
return this;
}

public AdaptAttributeBuilder PreserveReference(bool value)


/// <summary>
/// Configures whether to preserve object references during mapping.
/// </summary>
/// <param name="value">A boolean value indicating whether to preserve object references.</param>
/// <returns></returns>
public AdaptAttributeBuilder PreserveReference(bool value)
{
this.Attribute.PreserveReference = value;
return this;
}

public AdaptAttributeBuilder ShallowCopyForSameType(bool value)


/// <summary>
/// Configures whether to perform a shallow copy for the same source and destination type.
/// </summary>
/// <param name="value">A boolean value indicating whether to perform a shallow copy.</param>
/// <returns></returns>
public AdaptAttributeBuilder ShallowCopyForSameType(bool value)
{
this.Attribute.ShallowCopyForSameType = value;
return this;
}

public AdaptAttributeBuilder AlterType<TFrom, TTo>()

/// <summary>
/// Forward property types.
/// </summary>
/// <typeparam name="TFrom">Forward property from type.</typeparam>
/// <typeparam name="TTo">Forward property to type.</typeparam>
/// <returns></returns>
public AdaptAttributeBuilder AlterType<TFrom, TTo>()
{
this.AlterTypes.Add(type => type == typeof(TFrom) ? typeof(TTo) : null);
return this;
}

public AdaptAttributeBuilder AlterType(Func<Type, bool> predicate, Type toType)

/// <summary>
/// Forward property types for Code generation.
/// </summary>
/// <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>
/// <param name="toType">Type of destination to forward property type.</param>
/// <returns></returns>
public AdaptAttributeBuilder AlterType(Func<Type, bool> predicate, Type toType)
{
this.AlterTypes.Add(type => predicate(type) ? toType : null);
return this;
Expand Down
Loading