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

  • Home
  • SEARCH
  • 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 3225102
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:18:02+00:00 2026-05-17T16:18:02+00:00

I have some objects like user, address and so on, and Im converting them

  • 0

I have some objects like user, address and so on, and Im converting them to business objects using extension methods:

public static UserModel ToPresentationForm(this User pUser)
    {
        return new UserModel
        {
          ...
          map data
          ...
        };
    }

Also I need to convert strongly typed collections and usually I have the following code:

public static List<UserModel> ToPresentationForm(this List<User> pUserColl)
    {
        return pUserColl.Select(x => x.ToPresentationForm()).ToList();
    }

I was thinking, what if I add some interface, like IPresentationForms and will be able to use it, to write method like

public static List<T> ToPresentationForm(this List<IPresentationForms> pTemplate)
    {
        return pUserColl.Select(x => x.ToPresentationForm()).ToList();
    }

Not sure how to provide parameter to method type to make it generic. So the actual question is, how to do that.

P.S. Im using C# 4.0

  • 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-05-17T16:18:03+00:00Added an answer on May 17, 2026 at 4:18 pm

    Unfortunately since there is likely no relationship between User and UserModel, there is no way to create an interface to do what you want.

    On the other hand, let’s say that User and UserModel both implement the IUser interface. Then you could have an interface like this:

    interface IPresentationForms<T>
    {
        T ToPresentationForm();
    }
    

    And you could define User like this:

    class User: IUser, IPresentationForms<IUser>
    {
        public IUser ToPresentationForm()
        {
            return new UserModel(...);
        }
        .... // implement IUser
    }
    

    That could enable you to define ToPresentationForm something like this:

    public static List<T> ToPresentationForm<T>(this IEnumerable<T> pTemplate)
        where T : IPresentationForms<T>
    {    
        return pTemplate.Select(x => x.ToPresentationForm()).ToList();    
    }    
    

    That’s a lot of work to do to avoid a few extra methods.

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

Sidebar

Related Questions

I have some codes like this: cats = Category.objects.filter(is_featured=True) for cat in cats: entries
I have a set of objects I'd like to do some operations on, in
Let's say I have some model objects that resemble this: public class FooModel {
I have some objects inside of svg that can be clicked by user. Is
Hi have some objects in rails of Story, Likes And User I want to
Ok, let's imagine I have an object like this: public class User { public
Suppose I have some XML Like this: <User> <Name>X</Name> <Gender>Y</Gender> <ImageUrl>Z</ImageUrl> </User> and I
I have a LINQ query that returns some object like this... var query =
Say I have a structure like: class SomeObject Public Name as String Public Created
I have some objects which will be used in the same manor. This object

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.