示例#1
0
        /// <summary>
        /// Maps the array of <typeparamref name="TSource"/> into an array of
        /// <typeparamref name="TDestination"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="source">The source objects.</param>
        /// <returns>An array of <typeparamref name="TDestination"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
        /// <c>null</c>.</exception>
        public static TDestination[] MapArray <TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            TSource[] source)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var destination = new TDestination[source.Length];

            for (var i = 0; i < source.Length; ++i)
            {
                var sourceItem      = source[i];
                var destinationItem = mapper.Map(sourceItem);
                destination[i] = destinationItem;
            }

            return(destination);
        }
示例#2
0
        /// <summary>
        /// Maps the enumerable of <typeparamref name="TSource"/> into an array of
        /// <typeparamref name="TDestination"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="source">The source objects.</param>
        /// <returns>An array of <typeparamref name="TDestination"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
        /// <c>null</c>.</exception>
        public static TDestination[] MapArray <TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            IEnumerable <TSource> source)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var destination = new TDestination[source.Count()];
            var i           = 0;

            foreach (var sourceItem in source)
            {
                var destinationItem = mapper.Map(sourceItem);
                destination[i] = destinationItem;
                ++i;
            }

            return(destination);
        }
示例#3
0
        /// <summary>
        /// Maps the array of <typeparamref name="TSource"/> into a list of
        /// <typeparamref name="TDestination"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="source">The source objects.</param>
        /// <returns>A list of <typeparamref name="TDestination"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
        /// <c>null</c>.</exception>
        public static List <TDestination> MapList <TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            TSource[] source)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var destination = new List <TDestination>(source.Length);

            for (var i = 0; i < source.Length; ++i)
            {
                var sourceItem      = source[i];
                var destinationItem = mapper.Map(sourceItem);
                destination.Insert(i, destinationItem);
            }

            return(destination);
        }
示例#4
0
        /// <summary>
        /// Maps the collection of <typeparamref name="TSource"/> into an array of
        /// <typeparamref name="TDestination"/>.
        /// </summary>
        /// <typeparam name="TSourceCollection">The type of the source collection.</typeparam>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="sourceCollection">The source collection.</param>
        /// <param name="destinationCollection">The destination collection.</param>
        /// <returns>An array of <typeparamref name="TDestination"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="sourceCollection"/> is
        /// <c>null</c>.</exception>
        public static TDestination[] MapArray <TSourceCollection, TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            TSourceCollection sourceCollection,
            TDestination[] destinationCollection)
            where TSourceCollection : IEnumerable <TSource>
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (sourceCollection == null)
            {
                throw new ArgumentNullException(nameof(sourceCollection));
            }

            if (destinationCollection == null)
            {
                throw new ArgumentNullException(nameof(destinationCollection));
            }

            var i = 0;

            foreach (var item in sourceCollection)
            {
                var destination = mapper.Map(item);
                destinationCollection[i] = destination;
                ++i;
            }

            return(destinationCollection);
        }
示例#5
0
        /// <summary>
        /// Maps the collection of <typeparamref name="TSource"/> into a collection of
        /// <typeparamref name="TDestination"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="source">The source objects.</param>
        /// <returns>A collection of <typeparamref name="TDestination"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
        /// <c>null</c>.</exception>
        public static Collection <TDestination> MapCollection <TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            Collection <TSource> source)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var destination = new Collection <TDestination>();

            for (var i = 0; i < source.Count; ++i)
            {
                var sourceItem      = source[i];
                var destinationItem = mapper.Map(sourceItem);
                destination.Insert(i, destinationItem);
            }

            return(destination);
        }
示例#6
0
        /// <summary>
        /// Maps the collection of <typeparamref name="TSource" /> into a collection of type
        /// <typeparamref name="TDestinationCollection" /> containing objects of type <typeparamref name="TDestination" />.
        /// </summary>
        /// <typeparam name="TSourceCollection">The type of the source collection.</typeparam>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestinationCollection">The type of the destination collection.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="sourceCollection">The source collection.</param>
        /// <param name="destinationCollection">The destination collection.</param>
        /// <returns>A collection of type <typeparamref name="TDestinationCollection"/> containing objects of type
        /// <typeparamref name="TDestination" />.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper" /> or <paramref name="sourceCollection" /> is
        /// <c>null</c>.</exception>
        public static TDestinationCollection MapCollection <TSourceCollection, TSource, TDestinationCollection, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            TSourceCollection sourceCollection,
            TDestinationCollection destinationCollection)
            where TSourceCollection : IEnumerable <TSource>
            where TDestinationCollection : ICollection <TDestination>
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (sourceCollection == null)
            {
                throw new ArgumentNullException(nameof(sourceCollection));
            }

            foreach (var item in sourceCollection)
            {
                var destination = mapper.Map(item);
                destinationCollection.Add(destination);
            }

            return(destinationCollection);
        }
示例#7
0
 public MutationResolver(
     IImmutableMapper <HumanInput, Human> humanInputToHumanMapper,
     IHumanRepository humanRepository,
     ITopicEventSender topicEventSender)
 {
     this.humanInputToHumanMapper = humanInputToHumanMapper;
     this.humanRepository         = humanRepository;
     this.topicEventSender        = topicEventSender;
 }
        public async Task <Customer> CreateCustomerAsync(
            [Service] IImmutableMapper <CustomerInput, Customer> customerInputToCustomerMapper,
            [Service] ICustomerRepository customerRepository,
            CustomerInput customerInput,
            CancellationToken cancellationToken)
        {
            var customer = customerInputToCustomerMapper.Map(customerInput);

            customer = await customerRepository
                       .AddCustomerAsync(customer, cancellationToken)
                       .ConfigureAwait(false);

            return(customer);
        }
        public async Task <Human> CreateHumanAsync(
            [Service] IImmutableMapper <HumanInput, Human> humanInputToHumanMapper,
            [Service] IHumanRepository humanRepository,
            HumanInput humanInput,
            CancellationToken cancellationToken)
        {
            var human = humanInputToHumanMapper.Map(humanInput);

            human = await humanRepository
                    .AddHumanAsync(human, cancellationToken)
                    .ConfigureAwait(false);

            return(human);
        }
示例#10
0
        /// <summary>
        /// Maps the specified source object to a new object with a type of <typeparamref name="TDestination"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source object.</typeparam>
        /// <typeparam name="TDestination">The type of the destination object.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="source">The source object.</param>
        /// <returns>The mapped object of type <typeparamref name="TDestination"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper" /> or <paramref name="source" /> is
        /// <c>null</c>.</exception>
        public static TDestination Map <TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            TSource source)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(mapper.Map(source));
        }
        /// <summary>
        /// Maps the <see cref="IAsyncEnumerable{TSource}"/> into <see cref="IAsyncEnumerable{TDestination}"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="source">The source asynchronous enumerable.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>An <see cref="IAsyncEnumerable{TDestination}"/> collection.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
        /// <c>null</c>.</exception>
        public static async IAsyncEnumerable <TDestination> MapEnumerableAsync <TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            IAsyncEnumerable <TSource> source,
            [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            await foreach (var sourceItem in source.ConfigureAwait(false).WithCancellation(cancellationToken))
            {
                var destinationItem = mapper.Map(sourceItem);
                yield return(destinationItem);
            }
        }
示例#12
0
        /// <summary>
        /// Maps the enumerable of <typeparamref name="TSource"/> into a list of
        /// <typeparamref name="TDestination"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="source">The source objects.</param>
        /// <returns>A list of <typeparamref name="TDestination"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
        /// <c>null</c>.</exception>
        public static List <TDestination> MapList <TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            IEnumerable <TSource> source)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var destination = new List <TDestination>(source.Count());

            foreach (var sourceItem in source)
            {
                var destinationItem = mapper.Map(sourceItem);
                destination.Add(destinationItem);
            }

            return(destination);
        }
示例#13
0
        /// <summary>
        /// Maps the array of <typeparamref name="TSource"/> into a hash set of
        /// <typeparamref name="TDestination"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source objects.</typeparam>
        /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
        /// <param name="mapper">The mapper.</param>
        /// <param name="source">The source objects.</param>
        /// <returns>A hash set of <typeparamref name="TDestination"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
        /// <c>null</c>.</exception>
        public static HashSet <TDestination> MapHashSet <TSource, TDestination>(
            this IImmutableMapper <TSource, TDestination> mapper,
            TSource[] source)
        {
            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var destination = new HashSet <TDestination>();

            foreach (var sourceItem in source)
            {
                var destinationItem = mapper.Map(sourceItem);
                destination.Add(destinationItem);
            }

            return(destination);
        }
示例#14
0
 /// <summary>
 /// Maps the enumerable of <typeparamref name="TSource"/> into an immutable list of
 /// <typeparamref name="TDestination"/>.
 /// </summary>
 /// <typeparam name="TSource">The type of the source objects.</typeparam>
 /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
 /// <param name="mapper">The mapper.</param>
 /// <param name="source">The source objects.</param>
 /// <returns>An immutable list of <typeparamref name="TDestination"/>.</returns>
 /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
 /// <c>null</c>.</exception>
 public static ImmutableList <TDestination> MapImmutableList <TSource, TDestination>(
     this IImmutableMapper <TSource, TDestination> mapper,
     IEnumerable <TSource> source) =>
 ImmutableList.Create(mapper.MapArray(source));
示例#15
0
 /// <summary>
 /// Maps the array of <typeparamref name="TSource"/> into an immutable array of
 /// <typeparamref name="TDestination"/>.
 /// </summary>
 /// <typeparam name="TSource">The type of the source objects.</typeparam>
 /// <typeparam name="TDestination">The type of the destination objects.</typeparam>
 /// <param name="mapper">The mapper.</param>
 /// <param name="source">The source objects.</param>
 /// <returns>An immutable array of <typeparamref name="TDestination"/>.</returns>
 /// <exception cref="ArgumentNullException">The <paramref name="mapper"/> or <paramref name="source"/> is
 /// <c>null</c>.</exception>
 public static ImmutableArray <TDestination> MapImmutableArray <TSource, TDestination>(
     this IImmutableMapper <TSource, TDestination> mapper,
     TSource[] source) =>
 ImmutableArray.Create(mapper.MapArray(source));