-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Mapster" Version="7.3.0" /> | ||
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Mapster; | ||
using MapsterMapper; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
var services = new ServiceCollection(); | ||
|
||
var config = TypeAdapterConfig.GlobalSettings; | ||
config.NewConfig<Poco, Dto>(); | ||
services.AddSingleton(config); | ||
services.AddScoped<IMapper, ServiceMapper>(); | ||
|
||
var provider = services.BuildServiceProvider(); | ||
var mapper = provider.GetRequiredService<IMapper>(); | ||
|
||
TypeAdapterConfig<Poco, Dto2>.NewConfig().Map(d => d.Name, s => s.Name + "_Mapster"); | ||
|
||
var dto = mapper.From(new Poco() { Name = "Test" }).AdaptToType<Dto>(); | ||
var dto2 = mapper.From(new Poco() { Name = "Test" }).AdaptToType<Dto2>(); | ||
|
||
Console.ReadLine(); | ||
|
||
class Poco | ||
{ | ||
public string Name { get; set; } | ||
} | ||
|
||
class Dto | ||
{ | ||
public string Name { get; set; } | ||
} | ||
|
||
class Dto2 | ||
{ | ||
public string Name { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters