问题
I'm currently using expressmapper.
And I'm facing an issue, when i try co map an object to another one (aka destination). I get NullReferenceException, what seems to happen is when object "source" has some complexe properties (non value type) and "destination" haven't initialized them (ie: destination.MyListOfThing = null) then expressmapper throw the exception. Also when working with IList, elements don't get copied.
I'm not sure it's a "by design" behaviour, because a versatile mapping framework is one where you don't have to know anything (except from the type maybe) of the source object.
Is this a bug or something you can configure?
Edit: here are my classes definitions:
public class MapSource
{
public int Id { get; set; }
public Guid Guid { get; set; }
public MapSource Parent { get; set; }
public List<MapSource> Children { get; set; }
public static implicit operator int(MapSource src)
{
return src.Id;
}
}
public class MapDestination
{
public int Id { get; set; }
public Guid Guid { get; set; }
public MapDestination Parent { get; set; }
public List<MapSource> Children { get; set; }
}
A script to populate one:
public static IEnumerable<object[]> Source
{
get
{
var src = new MapSource
{
Id = Guid.NewGuid().GetHashCode(),
Guid = Guid.NewGuid(),
Parent = new MapSource
{
Id = Guid.NewGuid().GetHashCode(),
Guid = Guid.NewGuid()
}
};
src.Children = Enumerable.Range(0, 3).Select(i => new MapSource
{
Id = Guid.NewGuid().GetHashCode(),
Guid = Guid.NewGuid()
}).ToList();
return new [] { new object[] { src }};
}
}
来源:https://stackoverflow.com/questions/36545384/can-expressmapper-copy-to-destination