Mapster seems to not know how to map a simple assignment
UPDATE 1:
I added a method Value() to get the value of the Guid, if instead of a method I use a property public Guid Value => _value
the mapping works.
I have an Id class
public class Id
{
private readonly Guid _value;
public Id(Guid id)
{
_value = id;
}
public static implicit operator Id(Guid value)
{
return new Id(value);
}
public static implicit operator Guid(Id value)
{
return value._value;
}
public Guid Value() => _value;
}
I have 2 classes
public class C1
{
public Guid Id { get; set; }
}
public class C2
{
public Id Id { get; set; }
}
When trying to map them out of the box it just doesn't work, it calls the constructor of the Id
class with an empty Guid.
I wrote a simple program where the assignment works just fine
Any ideas how to make this work?
Guid aGuidValue = Guid.NewGuid();
Id anIdValue = aGuidValue;
Guid anotherGuidValue = anIdValue;
Console.WriteLine(aGuidValue.Equals(anotherGuidValue));
var c1 = new C1() {Id = aGuidValue};
var c2 = c1.Adapt<C2>();
Console.WriteLine(aGuidValue.Equals(c2.Id));
Console.WriteLine(aGuidValue);
Console.WriteLine(c1.Id);
Console.WriteLine(c2.Id.Value());
Output
True
False
d46f8d3a-f055-47c8-8f03-17b4ae51a3a9
d46f8d3a-f055-47c8-8f03-17b4ae51a3a9
00000000-0000-0000-0000-000000000000
Up