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 8202279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:07:38+00:00 2026-06-07T07:07:38+00:00

I have an array of different object types (about 15 different types) , they

  • 0

I have an array of different object types (about 15 different types) , they are coming from 3rd party system.
For every type I need to make different transformation.
My original thought is to make some interface with transform function and for every type make a class and run it’s own implementation.
But like this I will need to make a really big if statement that checks the object type and make the mapping.

I am trying to learn something new here, so my question is there other ways to deal with this situation?

  • 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-07T07:07:41+00:00Added an answer on June 7, 2026 at 7:07 am

    Have you considered the possibility of using a Visitor?

    If you combine the visitor pattern with the use of dynamic, you could get a pretty simple implementation without any if or switch statements, or having to manually create a Type Dictionary with delegates, or similar alternatives.

    Using dynamic you can avoid implementing the “accept” part of the design pattern, which I assume is useful to you since these are external types you have no control over.

    Meaning, you create something like this:

    public interface IVisitor
        {
            void Visit(OneType element);
            void Visit(AnotherType element);
            ....
        }
    

    You implement that visitor, and can later call the implementation using:

    visitor.Visit((dynamic)objectToTransform);
    

    You would probably have to handle for exceptions regarding not having an appropriate overload for the Type.

    That would solve the part of the problem related to executing a separate method for each type.
    Now, depending on what you specifically need to do with each one, if you need automatic property mapping then AutoMapper could be very useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to archive an array of objects of several different types.
I have a scroll view, which contains about 40-50 objects of different types. The
Say I have an array of void pointer pointing to objects of different types
Let's say I have an array of objects with different specific generic types like
I have an array of different times that looks like this: 20120628061533.0, 20120628064851.0, 20120628064853.0,
I have a string array of 3 different command line commands. Instead of writing
I have a struct-array that contains details of different reports that can be run.
I have a 4D array of measurements in MATLAB. Each dimension represents a different
I have two different arrays. One array, a, for a list of people. My
How can I store arrays in single array? e.g. I have four different arrays,

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.