diff --git a/docs/en/Object-To-Object-Mapping.md b/docs/en/Object-To-Object-Mapping.md index f3eab7de67..40efdd7ee6 100644 --- a/docs/en/Object-To-Object-Mapping.md +++ b/docs/en/Object-To-Object-Mapping.md @@ -320,57 +320,22 @@ public class MyCustomUserMapper : IObjectMapper, ITransientDepend } ```` -ABP automatically discovers and registers the `MyCustomUserMapper` and it is automatically used whenever you use the `IObjectMapper` to map `User` to `UserDto`. - -A single class may implement more than one `IObjectMapper` each for a different object pairs. +ABP automatically discovers and registers the `MyCustomUserMapper` and it is automatically used whenever you use the `IObjectMapper` to map `User` to `UserDto`. A single class may implement more than one `IObjectMapper` each for a different object pairs. > This approach is powerful since `MyCustomUserMapper` can inject any other service and use in the `Map` methods. -#### Collection Mapping - -You only requires configuration of element types, not of any array or list type that might be used. - -For example, we might have a simple source and destination type: - -````csharp -public class Source -{ - public int Value { get; set; } -} - -public class Destination -{ - public int Value { get; set; } -} -```` - -All the basic generic collection types are supported: - -````csharp -IObjectMapper _objectMapper //inject it. - -var sources = new[] -{ - new Source { Value = 5 }, - new Source { Value = 6 }, - new Source { Value = 7 } -}; - -IEnumerable ienumerableDest = _objectMapper.Map>(sources); -ICollection icollectionDest = _objectMapper.Map>(sources); -ICollection collectionDest = _objectMapper.Map>(sources); -IList ilistDest = _objectMapper.Map>(sources); -List listDest = _objectMapper.Map>(sources); -Destination[] arrayDest = _objectMapper.Map(sources); -```` - -To be specific, the source collection types supported include: +Once you implement `IObjectMapper`, ABP can automatically convert a collection of `User` objects to a collection of `UserDto` objects. The following generic collection types are supported: * `IEnumerable` * `ICollection` * `Collection` * `IList` * `List` -* `T[]` +* `T[]` (array) + +**Example:** -> When mapping to an existing collection, the destination collection is cleared first. +````csharp +var users = await _userRepository.GetListAsync(); // returns List +var dtos = ObjectMapper.Map, List>(users); // creates List +````