I need to map a single fixed sized array array to multiple properties.
For example given this class:
public class Source
{
public int[] ItemArray{get;set} // always 4 items
}
I want to map the array to this class
public class Dest
{
public int Item1 { get; set; }
public int Item2 { get; set; }
public int Item3 { get; set; }
public int Item4 { get; set; }
}
Is there a simple way to do it with AutoMapper (without actually mapping each individual field)?
Create mappings for properties of Dest:
Usage:
UPDATE: No, there is no simple way. How AutoMapper will understand, that your property Foo should be mapped to element at index N in source property Bar? You should provide all this info.
UPDATE: From Automapper
So, yes. If naming structure does not match, you must specify custom mapping for members.
UPDATE:
Well, actually you can do all conversion manually (but I don’t think it’s much better way, especially if you have other properties which could be mapped by name):