Ken Baltrinic
unread,Oct 21, 2010, 1:50:45 PM10/21/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to AutoMapper-users
I am trying to do some post processing on a mapping of enumerations
and it appears that the enumeration that I get from AfterMap is a
LinFu proxy and any time I try to enumerate over it I get a
NullReferenceException. I am guessing that GetEnumerator is returning
null. Here is a quick test to demo the problem:
public class TestType //Note: problem does not appear if target type
if a primitive.
{
public int current { get; set; }
public int prior { get; set; }
}
Mapper.CreateMap<int, TestType>()
.ForMember(tt => tt.current, opt => opt.MapFrom(i => i))
.ForMember(tt => tt.prior, opt => opt.Ignore());
Mapper.CreateMap<IEnumerable<int>, IEnumerable<TestType>>()
.AfterMap((i, tt) =>
{
var prior = tt.First(); //Throws exception here. If I remove the
call to .First()...
foreach (var t in tt) //Then the same exception throws on this
line.
{
t.prior = prior.current;
prior = t;
}
});
[Test]
public void post_process_enumerable_mapping()
{
var actual = Mapper.Map<IEnumerable<int>, IEnumerable<TestType>>(
new[] { 1, 2, 3 });
Assert.That(actual, Has.Count.EqualTo(3));
}