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 to extend an existing application I made to make it set mixer
Is it possible to continue or extend an existing schema with MySQL Workbench? This
I want to use a temp directory that will be unique to this build.
I want to extend or add another method to an existing protocol. Although the
I want to extend a WPF application with database functionality. Which database engine would
I want to extend the basic ControlCollection in VB.NET so I can just add
In following code, I want to extend the behaviour of a class by deriving/subclassing
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know the

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.