Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created May 18, 2010 23:24
Show Gist options
  • Save jfromaniello/405711 to your computer and use it in GitHub Desktop.
Save jfromaniello/405711 to your computer and use it in GitHub Desktop.
public class Foo
{
public Foo()
{
items = new HashedSet<FooItem>();
//Items = new HashedSet<FooItem>();
}
private readonly ICollection<FooItem> items;
//this fail
public virtual ICollection<FooItem> Items
{
get { return items; }
}
//this works
//public virtual ICollection<FooItem> Items { get; private set; }
public string Test { get; set; }
}
public class FooItem
{
public string Test { get; set; }
}
public class Bar
{
public Bar() { Items = new List<BarItem>(); }
public ICollection<BarItem> Items { get; private set;}
public string Test { get; set; }
}
public class BarItem
{
public string Test { get; set; }
}
[TestFixture]
public class TestMapper
{
[Test]
public void Test()
{
AutoMapper.Mapper.CreateMap<Bar, Foo>()
.ForMember(m => m.Items, m => m.UseDestinationValue());
AutoMapper.Mapper.CreateMap<BarItem, FooItem>();
var bar = new Bar();
bar.Items.Add(new BarItem{Test = "Baz"});
var foo = AutoMapper.Mapper.Map<Bar, Foo>(bar);
foo.Items.Count.Should().Be.EqualTo(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment