Use case ForAllOtherMembers?
See original GitHub issueConsider two types with a large number of properties that will auto-map due to common names between them, say there are 30 such properties. However, you only want 10 of these to auto-map and the remaining 20 to be ignored and not mapped. Further, imagine that the remainder are to be auto-mapped from another type whose properties also line up; so, for that map, it is desired that the 20 will auto-map there, and the 10 here ignored there.
The accepted answer in discussion 4036 seems to say you should “manually / explicitly” map the 10 properties (to use @jbogard 's language from the discussion) in the first map, and the 20 in the second, even though all 30 satisfy the auto-mapping convention, in that source and destination property names are identical.
Since these subsets of properties fit the use-case for auto-mapping, there should be a way to tell AutoMapper to auto-map just the subset of properties but ignore the rest.
Suppose there was an overload of ForMember() that only took one argument, a selector for the properties to auto-map. Something like, .ForMember(x=>new[]{x.Prop1, x.Prop2, ..., x.PropN}) , where you list the properties you want auto-mapped from the source, but you didn’t have to explicitly give the source properties in a MapFrom argument for each, since they all had the same names anyway, so should not have to be explicitly listed (back to manual mapping).
With a solution like this one, Ignore with ForAllOtherMembers seems to now have a use case, since for the 10-map, you need to ignore the remaining 20, and for the 20-map, you need to ignore the 10.
Issue Analytics
- State:
- Created a month ago
- Comments:5 (3 by maintainers)
Top Related StackOverflow Question
AutoMapper was designed for 95-100% similarity. Not 2/3. Even 90% would be the threshold of ditching AutoMapper for me.
Merging multiple objects was not the point of the example, but ok. The request is to give a user a way to configure a “threshold of similarity” that makes using your library worthwhile in their given situation. For example, a 2/3 or 3/4 or 5/6 “similarity” (common property names) between types seems like something AutoMapper was designed for, and 2/3 is very manageable when the source type has, say, 6 properties with the same names as a target type where only 2 must be ignored and the rest are auto-mapped. But in the earlier example, if 20 must be mapped and 10 ignored, (all 30 have the same names), then it’s still 2/3 similarity but now “not what AutoMapper was designed for”. Confusing.