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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:28:11+00:00 2026-05-17T00:28:11+00:00

Is it possible to get the parent object from a child object dynamically? Essentially,

  • 0

Is it possible to get the parent object from a child object dynamically? Essentially, all I’m trying to accomplish is to dynamically retrieve the value of a property belonging to a child objects’ parent. For example, something along the lines of the following:

public T GetParentProperty<T>(object oChildObject, string sPropertyName)
{
    ??? oOwner;
    PropertyInfo oOwnerInfo;
    T oPropertyValue;

    try
    {
        oPropertyValue = null;
        if (oChildObject != null)
        {
            oOwner = oChildObject.GetType().???;
            oOwnerInfo = oOwner.GetType().GetProperty(sPropertyName);
            if (oOwnerInfo != null)
                oPropertyValue = oOwnerInfo.GetValue(oOwner, null) as T;
        }
    }
    catch(Exception oEx)
    {
        Console.WriteLine(oEx);
    }

    return oPropertyValue;
}

Many thanks in advance!

  • 1 1 Answer
  • 1 View
  • 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-17T00:28:12+00:00Added an answer on May 17, 2026 at 12:28 am

    Assuming you mean “Parent” as in the class that your child inherits from, you can use the BaseType property of the Type Class. If the BaseType property doesn’t return exactly what you need, then you can look through the list of members at that link, and find the one that does. This is what you code example appears to be attempting.

    Unfortunately, if you mean “Parent” as in the class that owns the reference to your child type, I don’t think this can be done.

    I’m wondering why you need this functionality though, as it is a strange need.

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

Sidebar

Related Questions

is it possible to retrieve all children of a certain type from a parent
Possible Duplicate: Get all files from VSS for a given date? I need to
Is it possible for a child process to inherit a handle from its parent
Possible Duplicate: Error : get property of non-object I am new to codeigniter model,
i'm trying to get back a style property in all valid 'length' and 'percent'
I am trying to work out if it is possible get JPA to persist
Possible Duplicate: Get file name from URI string in C# How to extract file
Possible Duplicate: Get URL of ASP.Net Page in code-behind I'm trying to hold current
class Parent(): def __init__(self): self.child = Child() class Child(): def __init__(self): # get Parent
I have 2 different object types stored in RavenDb, which are a parent/child type

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.