Created
May 18, 2010 23:24
-
-
Save jfromaniello/405711 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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