MapsterMapper / MapsterMapper/Mapster

DateTimeOffset to DateTime throws Mapster.CompileException

Open
#356 7 comments 2 reactions 1 assignee View on GitHub

@andrerav is already working on this.

Since Feb 19, 2022.

improvement
Dominant language
C#
Stars
5.2k
Forks
410
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Really useful package (thank you!), but I've encountered a small problem when mapping classes containing a DateTimeOffset.
Mapster throws a CompileException ("Error while compiling source").
Not sure if I'm supposed to handle this mapping manually somehow? But seems like this could be handled automatically.

Repro example:

```
public class ExampleSource
{
public DateTimeOffset DateOfBirth { get; set; }
}

public class ExampleTarget
{
public DateTime DateOfBirth { get; set; }
}

public static void Test()
{
try
{
ExampleSource source = new ExampleSource() { DateOfBirth = DateTimeOffset.UtcNow };
ExampleTarget target = source.Adapt();

Console.WriteLine(target.DateOfBirth);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}

```

Expected output: Today's date/time
Actual output: "Error while compiling" (Mapster.CompileException)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.