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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:57:16+00:00 2026-05-31T17:57:16+00:00

is short: How can I invoke a base ctor after a child class ctor,

  • 0

is short:

How can I invoke a base ctor after a child class ctor, without adding extra code in the child class ctor?

the entire story:

I have a base class ctor which loops through its child’s properties with reflection.
the only problem is that it must be called after thier initialization, which happens in the child class ctor.

public class Parent
{
    public Parent()
    {
        DoReflectionStuff();
    }

    private void DoReflectionStuff()
    {
        // Do reflection stuff on child's properties
    }
}

public class Child : Parent
{
    public string Name { get; private set; }

    public int Age { get; private set; }

    public Child(string Name, int Age) : base()
    {
        this.Name = Name;
        this.Age = Age;
    }
}

I do not want to add extra code in the child ctor that calls DoReflectionSuff().

Please Help 🙂

Thank you

  • 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-31T17:57:17+00:00Added an answer on May 31, 2026 at 5:57 pm

    You can’t. The base ctor always has to run first.

    You might want to look into the factory method pattern in order to control construction and configuration before getting an instance of the class. You must use the factory method to construct an instance of the class, and the factory method always ensures the instance is configured correctly before returning it.

    public abstract class Parent
    {
        protected Parent(){}
    
        private void DoReflectionStuff()
        {
            // Do reflection stuff on child's properties
        }
    
        public static T Create<T>() where T : Parent
        {
            var temp = Activator.CreateInstance<T>();
            temp.DoReflectionStuff();
            return temp;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody have a short code sample that can be run in the VS
Short story: I can't make precompiled headers work properly with gcc -c option. Long
Can anyone show a short and simple code snippet? It should take the name
I wonder if someone can help: Long story short, I'm using MSSQL2005 to build
Ok, long story short I have a Windows service that handles Win32_VolumeChangeEvent and logs
Short version: How can I map two columns from table A and B if
SHORT VERSION OF QUESTION: So basically my question is: How can I set the
The short version of the question - why can't I do this? I'm restricted
So the short version of this is: Can I traverse only the elements within
How can i shorter below codes than before? i need short and simple method:

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.