Skip to content

Commit

Permalink
When using fields - not properties inside of ".Member" - throws Excep…
Browse files Browse the repository at this point in the history
…tion #59
  • Loading branch information
anisimovyuriy committed Nov 15, 2015
1 parent 4514bdc commit 52dc59a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ExpressMapper NET40/MemberConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public IMemberConfiguration<T, TN> Member<TMember, TNMember>(Expression<Func<TN,

var propertyInfo = typeof(TN).GetProperty(memberExpression.Member.Name);

if (propertyInfo.CanWrite && propertyInfo.GetSetMethod(true).IsPublic)
if (propertyInfo != null && !propertyInfo.CanWrite || (propertyInfo != null && propertyInfo.CanWrite && !propertyInfo.GetSetMethod(true).IsPublic))
{
Ignore(dest);
}
else
{
foreach (var typeMapper in _typeMappers)
{
Expand All @@ -79,7 +83,11 @@ public IMemberConfiguration<T, TN> Function<TMember, TNMember>(Expression<Func<T

var propertyInfo = typeof(TN).GetProperty(memberExpression.Member.Name);

if (propertyInfo.CanWrite && propertyInfo.GetSetMethod(true).IsPublic)
if (propertyInfo != null && !propertyInfo.CanWrite && !propertyInfo.GetSetMethod(true).IsPublic)
{
Ignore(dest);
}
else
{
foreach (var typeMapper in _typeMappers)
{
Expand Down
18 changes: 18 additions & 0 deletions ExpressMapper.Tests NET40/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ public void FieldsTest()
Assert.AreEqual(bvm, srcAndDest.Value);
}

[Test]
public void CustomMemberAndFunctionFieldsTest()
{
Mapper.Register<Brand, BrandViewModel>();
Mapper.Register<Table, TableViewModel>()
.Member(t => t.Id, t => t.Id)
.Function(t => t.Name, t => t.Name);
Mapper.Register<Size, SizeViewModel>();
Mapper.Register<Country, CountryViewModel>();
Mapper.Compile();

var srcAndDest = Functional.FieldsTestMap();

var bvm = Mapper.Map<Table, TableViewModel>(srcAndDest.Key);

Assert.AreEqual(bvm, srcAndDest.Value);
}

[Test]
public void MappingOrderLessTest()
{
Expand Down

0 comments on commit 52dc59a

Please sign in to comment.