Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Non-static method requires a target #137

Open
Jerome2606 opened this issue Mar 24, 2017 · 1 comment
Open

Non-static method requires a target #137

Jerome2606 opened this issue Mar 24, 2017 · 1 comment
Assignees
Labels

Comments

@Jerome2606
Copy link

Hello,

I try to map two class TaskEntity and TaskListItem like that:

Mapper.Register<TaskEntity, TaskListItem>() .Member(dst => dst.AddressValue, src => src.Addresses.ToString()) .Member(dst => dst.AssignedValue, src => EvaluateList(src.TaskUsers, t => t.RoleType == Enums.RoleTypeEnum.Assigned).UserName) .Member(dst => dst.CompleteDateValue, src => src.DeliveryDate) .Member(dst => dst.DeadlineValue, src => src.Deadline) .Member(dst => dst.LessorValue, src => EvaluateList(src.TaskUsers, t => t.RoleType == Enums.RoleTypeEnum.OfficeManager).UserName) .Member(dst => dst.StatusValue, src => src.TaskStatus.Description) .Member(dst => dst.SynchDateValue, src => src.CreationTime) .Member(dst => dst.TemplateTypeValue, src => src.Template.TemplateType.NameKey) .Member(dst => dst.TenantValue, src => EvaluateList(src.TaskUsers, t => t.RoleType == Enums.RoleTypeEnum.CustomerManager).UserName) .Member(dst => dst.TypeOfMissionValue, src => src.ContractType);

I use it like:

List<TaskListItem> taskItems = (List<TaskListItem>) taskEntities.Map(typeof (List<TaskEntity>), typeof (List<TaskListItem>));

And I get this error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetException: Non-static method requires a target.

Can you help me to understand why I get this error ?

@anisimovyuriy
Copy link
Member

anisimovyuriy commented Jul 28, 2017

Hi @Jerome2606,

I think you need to use .Function instead of .Member when you try to use MethodCallExpression in other words when you have .Member(dst => dst.AssignedValue, src => EvaluateList(src.TaskUsers, t => t.RoleType == Enums.RoleTypeEnum.Assigned).UserName) rewrite it to .Function(dst => dst.AssignedValue, src => EvaluateList(src.TaskUsers, t => t.RoleType == Enums.RoleTypeEnum.Assigned).UserName)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants