Skip to content

Commit

Permalink
Add Support for MapToDictionary and MapToDictionaryAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Feb 14, 2024
1 parent 4c24596 commit ae26dd5
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.5</Version>
<Version>0.0.0.7</Version>
<Description>Map objects.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>map,mapper,clone,coppy</PackageTags>
Expand All @@ -23,7 +23,7 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="AutoMapper">
<Version>12.0.1</Version>
<Version>13.0.1</Version>
</PackageReference>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public AutoMapperProvider(MapperConfiguration mapperConfiguration)
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override TTo Map<TTo>(object fromObject, string uniqueRecordId = default, string language = default, params object[] parameters)
public override TTo Map<TTo>(object fromObject, string uniqueIdentity = default, string language = default, params object[] parameters)
{
return _mapper.Map<TTo>(fromObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.6</Version>
<Version>0.0.0.7</Version>
<Description>Map objects.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>map,mapper,clone,coppy</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@ public interface IMapper<TFrom, TTo> : IMapper
///
/// </summary>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public TTo Map(TFrom fromObject, string uniqueRecordId, string language, object[] parameters);
public TTo Map(TFrom fromObject, string uniqueIdentity, string language, object[] parameters);

/// <summary>
///
/// </summary>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public TFrom Map(TTo fromObject, string uniqueRecordId, string language, object[] parameters);
public TFrom Map(TTo fromObject, string uniqueIdentity, string language, object[] parameters);
/// <summary>
///
/// </summary>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public Task<TTo> MapAsync(TFrom fromObject, string uniqueRecordId, string language, object[] parameters);
public Task<TTo> MapAsync(TFrom fromObject, string uniqueIdentity, string language, object[] parameters);

/// <summary>
///
/// </summary>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public Task<TFrom> MapAsync(TTo fromObject, string uniqueRecordId, string language, object[] parameters);
public Task<TFrom> MapAsync(TTo fromObject, string uniqueIdentity, string language, object[] parameters);
}

/// <summary>
Expand All @@ -58,19 +58,19 @@ public interface IMapper
///
/// </summary>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public object MapObject(object fromObject, string uniqueRecordId, string language, object[] parameters);
public object MapObject(object fromObject, string uniqueIdentity, string language, object[] parameters);
/// <summary>
///
/// </summary>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public Task<object> MapObjectAsync(object fromObject, string uniqueRecordId, string language, object[] parameters);
public Task<object> MapObjectAsync(object fromObject, string uniqueIdentity, string language, object[] parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ void AddMapperForType(Type fromType, Type toType, IMapper mapper)
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override TTo Map<TTo>(object fromObject, string uniqueRecordId = null, string language = null, params object[] parameters)
public override TTo Map<TTo>(object fromObject, string uniqueIdentity = null, string language = null, params object[] parameters)
{
if (fromObject == null)
return default;
if (Mappers.TryGetValue(fromObject.GetType(), out Dictionary<Type, IMapper> mappers))
{
if (mappers.TryGetValue(typeof(TTo), out IMapper mapper))
{
return (TTo)mapper.MapObject(fromObject, uniqueRecordId, language, parameters);
return (TTo)mapper.MapObject(fromObject, uniqueIdentity, language, parameters);
}
}
if (_backupMapperProvider != null)
return _backupMapperProvider.Map<TTo>(fromObject, uniqueRecordId, language, parameters);
return _backupMapperProvider.Map<TTo>(fromObject, uniqueIdentity, language, parameters);
throw new Exception($"mapper not found for {fromObject.GetType()} and {typeof(TTo)}");
}

Expand All @@ -90,24 +90,24 @@ public override TTo Map<TTo>(object fromObject, string uniqueRecordId = null, st
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public override async Task<TTo> MapAsync<TTo>(object fromObject, string uniqueRecordId = null, string language = null, params object[] parameters)
public override async Task<TTo> MapAsync<TTo>(object fromObject, string uniqueIdentity = null, string language = null, params object[] parameters)
{
if (fromObject == null)
return default;
if (Mappers.TryGetValue(fromObject.GetType(), out Dictionary<Type, IMapper> mappers))
{
if (mappers.TryGetValue(typeof(TTo), out IMapper mapper))
{
return (TTo)await mapper.MapObjectAsync(fromObject, uniqueRecordId, language, parameters);
return (TTo)await mapper.MapObjectAsync(fromObject, uniqueIdentity, language, parameters);
}
}
if (_backupMapperProvider != null)
return await _backupMapperProvider.MapAsync<TTo>(fromObject, uniqueRecordId, language, parameters);
return await _backupMapperProvider.MapAsync<TTo>(fromObject, uniqueIdentity, language, parameters);
throw new Exception($"mapper not found for {fromObject.GetType()} and {typeof(TTo)}");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net45</TargetFrameworks>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.3</Version>
<Version>0.0.0.7</Version>
<Description>Map objects.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>map,mapper,clone,coppy</PackageTags>
Expand All @@ -16,7 +16,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization" Version="0.0.0.4" />
<PackageReference Include="EasyMicroservices.Serialization" Version="0.0.0.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public SerializerMapperProvider(IBinarySerializationProvider binarySerialization
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override TTo Map<TTo>(object fromObject, string uniqueRecordId = default, string language = default, params object[] parameters)
public override TTo Map<TTo>(object fromObject, string uniqueIdentity = default, string language = default, params object[] parameters)
{
if (_textSerialization != null)
return _textSerialization.Deserialize<TTo>(_textSerialization.Serialize(fromObject));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Serialization.BinaryGo" Version="0.0.0.4" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.6" />
<PackageReference Include="EasyMicroservices.Serialization.System.Text.Json" Version="0.0.0.7" />
<PackageReference Include="EasyMicroservices.Tests" Version="0.0.0.7" />
<PackageReference Include="EasyMicroservices.Serialization.BinaryGo" Version="0.0.0.9" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.9" />
<PackageReference Include="EasyMicroservices.Serialization.System.Text.Json" Version="0.0.0.9" />
<PackageReference Include="EasyMicroservices.Tests" Version="0.0.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit.assert" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.5</Version>
<Version>0.0.0.7</Version>
<Description>Map objects.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>map,mapper,clone,coppy</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,61 @@ public interface IMapperProviderAsync
/// <typeparam name="TFrom">map from object type</typeparam>
/// <typeparam name="TTo">map to object type</typeparam>
/// <param name="fromObject">object to map</param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns>mapped object</returns>
Task<TTo> MapAsync<TFrom, TTo>(TFrom fromObject = default, string uniqueRecordId = default, string language = default, params object[] parameters);
Task<TTo> MapAsync<TFrom, TTo>(TFrom fromObject = default, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
/// map an object to another object
/// </summary>
/// <typeparam name="TTo">map to object type</typeparam>
/// <param name="fromObject">object to map</param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns>mapped object</returns>
Task<TTo> MapAsync<TTo>(object fromObject, string uniqueRecordId = default, string language = default, params object[] parameters);
Task<TTo> MapAsync<TTo>(object fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
/// map enumerable to a list
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
Task<List<TTo>> MapToListAsync<TTo>(IEnumerable fromObject, string uniqueRecordId = default, string language = default, params object[] parameters);
Task<List<TTo>> MapToListAsync<TTo>(IEnumerable fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
///
/// </summary>
/// <typeparam name="TFrom"></typeparam>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
Task<List<TTo>> MapSingleToListAsync<TTo>(object fromObject, string uniqueRecordId = default, string language = default, params object[] parameters);
Task<Dictionary<TFrom, TTo>> MapToDictionaryAsync<TFrom, TTo>(IEnumerable<TFrom> fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
///
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
Task<List<TTo>> MapSingleToListAsync<TTo>(object fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
/// map a list to first item
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
Task<TTo> MapToFirstAsync<TTo>(IEnumerable fromObject, string uniqueRecordId = default, string language = default, params object[] parameters);
Task<TTo> MapToFirstAsync<TTo>(IEnumerable fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,61 @@ public interface IMapperProviderSync
/// <typeparam name="TFrom">map from object type</typeparam>
/// <typeparam name="TTo">map to object type</typeparam>
/// <param name="fromObject">object to map</param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns>mapped object</returns>
TTo Map<TFrom, TTo>(TFrom fromObject = default, string uniqueRecordId = default, string language = default, params object[] parameters);
TTo Map<TFrom, TTo>(TFrom fromObject = default, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
/// map an object to another object
/// </summary>
/// <typeparam name="TTo">map to object type</typeparam>
/// <param name="fromObject">object to map</param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns>mapped object</returns>
TTo Map<TTo>(object fromObject, string uniqueRecordId = default, string language = default, params object[] parameters);
TTo Map<TTo>(object fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
/// map enumerable to a list
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
List<TTo> MapToList<TTo>(IEnumerable fromObject, string uniqueRecordId = default, string language = default, params object[] parameters);
List<TTo> MapToList<TTo>(IEnumerable fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
///
/// </summary>
/// <typeparam name="TFrom"></typeparam>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
List<TTo> MapSingleToList<TTo>(object fromObject, string uniqueRecordId = default, string language = default, params object[] parameters);
Dictionary<TFrom, TTo> MapToDictionary<TFrom, TTo>(IEnumerable<TFrom> fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
///
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
List<TTo> MapSingleToList<TTo>(object fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
/// <summary>
/// map a list to first item
/// </summary>
/// <typeparam name="TTo"></typeparam>
/// <param name="fromObject"></param>
/// <param name="uniqueRecordId"></param>
/// <param name="uniqueIdentity"></param>
/// <param name="language"></param>
/// <param name="parameters"></param>
/// <returns></returns>
TTo MapToFirst<TTo>(IEnumerable fromObject, string uniqueRecordId = default, string language = default, params object[] parameters);
TTo MapToFirst<TTo>(IEnumerable fromObject, string uniqueIdentity = default, string language = default, params object[] parameters);
}
}
Loading

0 comments on commit ae26dd5

Please sign in to comment.