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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:03:31+00:00 2026-06-08T12:03:31+00:00

I need to convert one object to another…in both cases of a single instance

  • 0

I need to convert one object to another…in both cases of a single instance of the object as well as corresponding Lists of those objects. I’d rather not have to perform the same mappings in 2 places. Here is what I mean:
This converts a Facebook movie to a Standard Movie object

//Converts an Facebook object to a Standard Movie object
    public MovieDetails ConvertFacebookMovieToStandardMovie(FacebookMovie Movies)
    {
        MovieDetails objMovieDetails = new MovieDetails();
        objMovieDetails.ID = 0;
        objMovieDetails.Source = Movies.Source;
        objMovieDetails.SourceID = Convert.ToString(Movies.ID);
        objMovieDetails.Title = Movies.Name;
        objMovieDetails.URL = GetInternalMovieURL(objMovieDetails.Source, objMovieDetails.SourceID);
        objMovieDetails.ImageURL = Movies.Picture;
        objMovieDetails.SourceURL = Movies.SourceURL;
        objMovieDetails.Description = Movies.Description

        return objMovieDetails;

    }//Convert Facebook to standard

Now I also need to do the same things in cases where I have the same objects, just in List form, i.e.

//Converts an Facebook class to a MovieDetails class of WWN
    public List<MovieDetails> ConvertFacebookMovieToStandardMovie(List<FacebookMovie> lstFacebookMovieDetails)
    {
        List<MovieDetails> lstMovieListDetails = lstFacebookMovieDetails.Select(Movies => new MovieDetails()
        {
            ID = 0
            ,Source = Movies.Source
            ,SourceID = Convert.ToString(Movies.ID)
            ,Title = Movies.Name
            ,URL = GetInternalMovieURL(Source, SourceID)
            ,ImageURL = Movies.Picture
            ,SourceURL = Movies.SourceURL
            ,Description = Movies.Description
        }).ToList();

        return lstMovieListDetails;

    }//Convert Facebook to standard

I’m new to c# and linq, so not sure how I could create one method that could handle both…or at least a way to encapsulate the mappings.

I know I could create an overload method for the List scenario and loop through the items in the list and call the first object convert method…But I was hoping to use the linq route I currently have for, what I’m guessing, is better performance.

Thanks!
Chad

  • 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-08T12:03:32+00:00Added an answer on June 8, 2026 at 12:03 pm

    Unless there’s a performance gain on having separate code for these two cases I’d simply scrap the single movie variant and keep the List variant. To do the single movie variant simply do this with using System.Linq;:

    List<FacebookMovie> moviesDetailsList = ...
    MovieDetails movieDetails = ConvertFacebookMovieToStandardMovie(moviesDetailsList).Single();
    

    If you want the single case as a separate method, you can place the above as the body of that method with “…” = new [] {movieDetail};

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

Sidebar

Related Questions

I have an single-dimensional array of PHP objects. Each object has two attributes, one
I'm using XStream to convert java objects to their XML counterparts. One such object
I have a collection of domain objects that I need to convert into another
I have the following array of objects which I need to convert to one
I need to convert a passed in argument (single object or collection) to an
I need to convert an open delegate (one in which the Target is not
I need to convert a VB Collection to a modern one, like Dictionary or
I need to convert my string date to datetime type. Here's one date scenario:
Here's a simple one for you guys. I need to convert the result of
I need to call Ghostscript in one of our cgi to convert a PDF

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.