Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="AutoMapper" Version="16.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutoMapper;
using Newtonsoft.Json;
using Microsoft.Extensions.Logging.Abstractions;
using System.Text.Json;

namespace AutoMapperIgnoreNullValues;

Expand All @@ -21,14 +22,14 @@ private static StudentEntity MapToStudentEntity<TProfile>(StudentItemDto source)
var config = new MapperConfiguration(cfg =>
{
cfg.AddProfile<TProfile>();
});
}, NullLoggerFactory.Instance);

IMapper mapper = config.CreateMapper();
var destination = GetSampleEntity();
destination = mapper.Map(source, destination);

Console.WriteLine("Destination : {0}",
JsonConvert.SerializeObject(destination, Formatting.Indented));
JsonSerializer.Serialize(destination, new JsonSerializerOptions { WriteIndented = true }));

if (destination.Department == null)
throw new ArgumentNullException("Department", "Department is null");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json;

namespace AutoMapperIgnoreNullValues;
internal class Program
Expand All @@ -13,7 +13,7 @@ static void Main(string[] args)
Grades = null
};

Console.WriteLine("\nSource : {0}", JsonConvert.SerializeObject(source, Formatting.Indented));
Console.WriteLine("\nSource : {0}", JsonSerializer.Serialize(source, new JsonSerializerOptions { WriteIndented = true }));

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

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Loading