In the "ProDinner" project, ValueInjecter is used for mapping.I use the newest version, which replace ConventionInjection with LoopInjection when convert between entities and int[],I have got the code of EntitiesToInts class:
public class EntitiesToInts : LoopInjection
{
protected override bool MatchTypes(Type src, Type trg)
{
return trg == typeof(int[])
&& src.IsGenericType
&& src.GetGenericTypeDefinition() == typeof(ICollection<>)
&& src.GetGenericArguments()[0].IsSubclassOf(typeof(Entity));
}
protected override void SetValue(object source, object target, PropertyInfo sp, PropertyInfo tp)
{
var val = sp.GetValue(source);
if (val != null)
{
tp.SetValue(target, (val as IEnumerable<Entity>).Select(o => o.Id).ToArray());
}
}
}
How to finish IntsToEntities class?