Skip to content

Commit

Permalink
Added basic implementations using AutoMapper and Mapster
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuck committed Dec 2, 2021
1 parent f2565d3 commit 025a203
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 18 deletions.
12 changes: 12 additions & 0 deletions YuckQi.Extensions.Mapping.Abstractions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YuckQi.Extensions.Mapping.Abstractions", "src\YuckQi.Extensions.Mapping.Abstractions\YuckQi.Extensions.Mapping.Abstractions.csproj", "{D96F4DBA-D0B0-4F27-8936-EE61E3D96CAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YuckQi.Extensions.Mapping.AutoMapper", "src\YuckQi.Extensions.Mapping.AutoMapper\YuckQi.Extensions.Mapping.AutoMapper.csproj", "{440E7587-1D82-41DE-B010-88A6F59E2345}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YuckQi.Extensions.Mapping.Mapster", "src\YuckQi.Extensions.Mapping.Mapster\YuckQi.Extensions.Mapping.Mapster.csproj", "{B3618BEC-AD2D-4305-87E9-2DAF8016BAA1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +19,14 @@ Global
{D96F4DBA-D0B0-4F27-8936-EE61E3D96CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D96F4DBA-D0B0-4F27-8936-EE61E3D96CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D96F4DBA-D0B0-4F27-8936-EE61E3D96CAE}.Release|Any CPU.Build.0 = Release|Any CPU
{440E7587-1D82-41DE-B010-88A6F59E2345}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{440E7587-1D82-41DE-B010-88A6F59E2345}.Debug|Any CPU.Build.0 = Debug|Any CPU
{440E7587-1D82-41DE-B010-88A6F59E2345}.Release|Any CPU.ActiveCfg = Release|Any CPU
{440E7587-1D82-41DE-B010-88A6F59E2345}.Release|Any CPU.Build.0 = Release|Any CPU
{B3618BEC-AD2D-4305-87E9-2DAF8016BAA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3618BEC-AD2D-4305-87E9-2DAF8016BAA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3618BEC-AD2D-4305-87E9-2DAF8016BAA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3618BEC-AD2D-4305-87E9-2DAF8016BAA1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions YuckQi.Extensions.Mapping.Abstractions.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mapster/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>1.0.0</Version>
<Description>Mapping abstractions for an object-to-object mapper.</Description>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Extensions.Mapping.Abstractions.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Yuck/YuckQi.Extensions.Mapping.Abstractions</PackageProjectUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>1.0.0</Version>
<Description>Mapping abstractions for an object-to-object mapper.</Description>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Extensions.Mapping.Abstractions.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Yuck/YuckQi.Extensions.Mapping.Abstractions</PackageProjectUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<None Update="readme.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<None Update="readme.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions src/YuckQi.Extensions.Mapping.AutoMapper/DefaultMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using AutoMapper;
using AutoMapperIMapper = AutoMapper.IMapper;
using IMapper = YuckQi.Extensions.Mapping.Abstractions.IMapper;

namespace YuckQi.Extensions.Mapping.AutoMapper
{
public class DefaultMapper : IMapper
{
#region Private Members

private readonly AutoMapperIMapper _mapper;

#endregion


#region Constructors

public DefaultMapper(IConfigurationProvider configuration)
{
if (configuration == null)
throw new ArgumentNullException(nameof(configuration));

_mapper = configuration.CreateMapper();
}

#endregion


#region Public Methods

public Object Map(Object source, Object destination, Type sourceType, Type destinationType) => _mapper.Map(source, destination, sourceType, destinationType);

public Object Map(Object source, Type sourceType, Type destinationType) => _mapper.Map(source, sourceType, destinationType);

public TDestination Map<TDestination>(Object source) => _mapper.Map<TDestination>(source);

public TDestination Map<TSource, TDestination>(TSource source) => _mapper.Map<TSource, TDestination>(source);

public TDestination Map<TSource, TDestination>(TSource source, TDestination destination) => _mapper.Map(source, destination);

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>1.0.0</Version>
<Description>A basic mapper implementation using the AutoMapper framework.</Description>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Extensions.Mapping.Abstractions.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Yuck/YuckQi.Extensions.Mapping.Abstractions</PackageProjectUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\YuckQi.Extensions.Mapping.Abstractions\YuckQi.Extensions.Mapping.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="readme.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/YuckQi.Extensions.Mapping.AutoMapper/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# YuckQi.Extensions.Mapping.Abstractions
42 changes: 42 additions & 0 deletions src/YuckQi.Extensions.Mapping.Mapster/DefaultMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using Mapster;
using MapsterMapper;
using IMapper = YuckQi.Extensions.Mapping.Abstractions.IMapper;
using MapsterIMapper = MapsterMapper.IMapper;

namespace YuckQi.Extensions.Mapping.Mapster
{
public class DefaultMapper : IMapper
{
#region Private Members

private readonly MapsterIMapper _mapper;

#endregion


#region Constructors

public DefaultMapper(TypeAdapterConfig configuration = null)
{
_mapper = configuration != null ? new Mapper(configuration) : new Mapper();
}

#endregion


#region Public Methods

public Object Map(Object source, Object destination, Type sourceType, Type destinationType) => _mapper.Map(source, destination, sourceType, destinationType);

public Object Map(Object source, Type sourceType, Type destinationType) => _mapper.Map(source, sourceType, destinationType);

public TDestination Map<TDestination>(Object source) => _mapper.Map<TDestination>(source);

public TDestination Map<TSource, TDestination>(TSource source) => _mapper.Map<TSource, TDestination>(source);

public TDestination Map<TSource, TDestination>(TSource source, TDestination destination) => _mapper.Map(source, destination);

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>1.0.0</Version>
<Description>A basic mapper implementation using the Mapster framework.</Description>
<RepositoryUrl>https://github.com/Yuck/YuckQi.Extensions.Mapping.Abstractions.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Yuck/YuckQi.Extensions.Mapping.Abstractions</PackageProjectUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mapster" Version="7.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\YuckQi.Extensions.Mapping.Abstractions\YuckQi.Extensions.Mapping.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="readme.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/YuckQi.Extensions.Mapping.Mapster/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# YuckQi.Extensions.Mapping.Abstractions

0 comments on commit 025a203

Please sign in to comment.