Skip to content

Commit 7ae00d7

Browse files
committed
map to ExpandoObject
1 parent 3481aee commit 7ae00d7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/AutoMapper/Mappers/MapperRegistry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public static List<IObjectMapper> Mappers() =>
1818
new ConstructorMapper(),// new Destination(source)
1919
new ConversionOperatorMapper("op_Implicit"),// implicit operator Destination or implicit operator Source
2020
new ConversionOperatorMapper("op_Explicit"),// explicit operator Destination or explicit operator Source
21-
new FromStringDictionaryMapper(),// property values to typed object
22-
new ToStringDictionaryMapper(),// typed object to property values
2321
new FromDynamicMapper(),// dynamic to typed object
2422
new ToDynamicMapper(),// typed object to dynamic
23+
new FromStringDictionaryMapper(),// property values to typed object
24+
new ToStringDictionaryMapper(),// typed object to property values
2525
];
2626
}

src/UnitTests/Mappers/DynamicMapperTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ public void Should_map_source_properties()
6767
Assert.Equal(12, _destination.Baz);
6868
((int[])_destination.Data).SequenceEqual(data).ShouldBeTrue();
6969
}
70+
[Fact]
71+
public void Should_map_to_ExpandoObject()
72+
{
73+
var config = new MapperConfiguration(cfg => { });
74+
var data = new[] { 1, 2, 3 };
75+
_destination = config.CreateMapper().Map<ExpandoObject>(new Destination { Foo = "Foo", Bar = "Bar", Data = data, Baz = 12 });
76+
((IDictionary<string, object>)_destination).Count.ShouldBe(4);
77+
Assert.Equal("Foo", _destination.Foo);
78+
Assert.Equal("Bar", _destination.Bar);
79+
Assert.Equal(12, _destination.Baz);
80+
((int[])_destination.Data).SequenceEqual(data).ShouldBeTrue();
81+
}
7082
}
7183

7284
public class When_mapping_from_dynamic

0 commit comments

Comments
 (0)