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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:27:40+00:00 2026-05-13T14:27:40+00:00

When I want to extend an existing Object I create my own and use

  • 0

When I want to extend an existing Object I create my own and use inherits clause, and works fantastic… problem is when I want to use this new Object instead of the original, the populate part is a “pain”.

is there any AUTO POPULATE way of doing this?

Original Object: Customer
My Object: CustomerWithGroup

public class CustomerWithGroup : Customer
{
    public CustomerWithGroup() { }
    public string GroupName { get; set; }
    public string Fullname
    {
        get
        {
            return string.Format("{0} {1} {2}", firstname, middlename, lastname).Replace("  ", " ");
        }
    }
}

and I’m populating it like this:

customerswithgroup = new List<CustomerWithGroup>();
string groupname;
foreach (Customer c in customers)
{
    groupname = customergroup.Find(x => x.customer_group_id == c.group_id).customer_group_code;

    customerswithgroups.Add(
        new CustomerWithGroup { 
            GroupName = groupname,
            created_at = c.created_at, customer_id = c.customer_id, default_billing = c.default_billing, default_shipping = c.default_shipping, email = c.email, firstname = c.firstname, group_id = c.group_id, increment_id = c.increment_id, lastname = c.lastname, middlename = c.middlename, password_hash = c.password_hash, prefix = c.prefix, store_id = c.store_id, suffix = c.suffix, taxvat = c.taxvat, updated_at = c.updated_at, website_id = c.website_id });
}

It’s a bunch of code! and you can imagine doing this for really big objects!

Ins’t there a way of telling, like

Hei object, please load all the base members from this Object!

newCG = new CustomerWithGroup().LoadFromBase(c);
newCG.groupName = "my group";
customerswithgroup.Add( newCG );

Is there any trick we can use?

  • 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-13T14:27:41+00:00Added an answer on May 13, 2026 at 2:27 pm

    No, there is no easy way. You could use reflection and write a bunch of code to do that, but it would be a lot of work.

    In my opinion you should rethink your design. Inheritance is not a good solution in this case, composition here is better, like so:

    public class CustomerWithGroups
    {
        public CustomerWithGroups(Customer c) { Customer = c; }
    
        public Customer Customer { get; private set; }
    
        public string GroupName { get; set; }
        public string Fullname
        {
            get
            {
                return string.Format("{0} {1} {2}", Customer.firstname, Customer.middlename, Customer.lastname).Replace("  ", " ");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create a new JavaScript object based on an existing JavaScript object. Till
I want to extend RuntimeException to create this specific exception: class CompileLinkException extends RuntimeException
I want to create a custom tag library which should extend the existing Spring
As I use Notepad++ daily at work, I want to extend it to be
Folks I have a sealed class as follows. I want to extend this sealed
I am currently trying to extend an existing project. Unfortunately I am completely new
I want to extend or add another method to an existing protocol. Although the
So what I want to do is extend the existing vector class in my
How do I extend an existing object method in jQuery? For instance, I'm using
We have an existing app that we want to add Analytics to. This link:

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.