Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7755399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:33:32+00:00 2026-06-01T12:33:32+00:00

I need to map a single fixed sized array array to multiple properties. For

  • 0

I need to map a single fixed sized array array to multiple properties.
For example given this class:

public class Source
{
    public int[] ItemArray{get;set} // always 4 items
}

I want to map the array to this class

public class Dest
{
    public int Item1 { get; set; }
    public int Item2 { get; set; }
    public int Item3 { get; set; }
    public int Item4 { get; set; }
}

Is there a simple way to do it with AutoMapper (without actually mapping each individual field)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:33:33+00:00Added an answer on June 1, 2026 at 12:33 pm

    Create mappings for properties of Dest:

    Mapper.CreateMap<Source, Dest>()
        .ForMember(d => d.Item1, o => o.MapFrom(s => s.ItemArray[0]))
        .ForMember(d => d.Item2, o => o.MapFrom(s => s.ItemArray[1]))
        .ForMember(d => d.Item3, o => o.MapFrom(s => s.ItemArray[2]))
        .ForMember(d => d.Item4, o => o.MapFrom(s => s.ItemArray[3]));
    

    Usage:

    Source source = new Source() { ItemArray = new int[] { 1, 2, 3, 4 } };
    Dest dest = Mapper.Map<Source, Dest>(source);
    

    UPDATE: No, there is no simple way. How AutoMapper will understand, that your property Foo should be mapped to element at index N in source property Bar? You should provide all this info.

    UPDATE: From Automapper

    Projection transforms a source to a destination beyond flattening the object model. Without extra configuration, AutoMapper requires a flattened destination to match the source type’s naming structure. When you want to project source values into a destination that does not exactly match the source structure, you must specify custom member mapping definitions.

    So, yes. If naming structure does not match, you must specify custom mapping for members.

    UPDATE:
    Well, actually you can do all conversion manually (but I don’t think it’s much better way, especially if you have other properties which could be mapped by name):

    Mapper.CreateMap<Source, Dest>().ConstructUsing((s) => new Dest()
    {
        Item1 = s.ItemArray[0],
        Item2 = s.ItemArray[1],
        Item3 = s.ItemArray[2],
        Item4 = s.ItemArray[3]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to map two tables to a single class, having trouble figuring this
I need to map a class which has a list of Enums to a
In php, I often need to map a variable using an array ... but
Is it possible in myBatis 3 to map a single result to multiple objects,
I have ID values of the type unsigned int . I need to map
I need to somehow convert a single json string into multiple objects of a
I need to copy multiple files in a single batch file. The files have
I need to write a map service that returns a single, static map image
Following this question: Shuffling numbers in a map and selecting one. Say you need
In a simple webapp I need to map URLs to filenames or filepaths. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.