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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:22:19+00:00 2026-06-13T18:22:19+00:00

I have to set a property inside an unknown object. The structure looks like

  • 0

I have to set a property inside an unknown object. The structure looks like this:

        ObjA.ObjB().ObjC.PropA = propValue;

ObjA is from a referenced class. ObjB() is of type object and therefore ObjC is unknown. I thought about using Reflection but don’t know how to use it correctly in this case.

        object objB = ObjA.ObjB();
        Type objBType = objB.GetType();
        System.Reflection.XXXInfo objCInfo = objBType.GetXXX("ObjC");

        Type objCType = objCInfo.GetType();
        System.Reflection.PropertyInfo PropAInfo = objCType.GetProperty("PropA");
        PropAInfo.SetValue(PropAInfo, propValue, null);

Answer (Thanks to BigM):

        dynamic objAB = ObjA.ObjB(); 
        objAB.ObjC.PropA = propValue;
  • 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-06-13T18:22:20+00:00Added an answer on June 13, 2026 at 6:22 pm

    This should probably work for you.

    object objB = ObjA.ObjB();
    Type objBType = objB.GetType();
    System.Reflection.PropertyInfo objCInfo = objBType.GetProperty("ObjC");
    object val = objCInfo.GetValue(objB);
    
    Type objCType = val.GetType();
    System.Reflection.PropertyInfo PropAInfo = objCType.GetProperty("PropA");
    PropAInfo.SetValue(val, propValue, null);
    

    However, I think a bit of re-architecting could be done here to make life a bit easier. For example, if you don’t know anything about the types then you might consider using dynamic and returning dynamic types from ObjC and PropA – but there is a performance hit there.

    On the other hand, if there is any way that you can use generics, that would make your life a lot easier. For example, the code here that sets the property value, if that method were generic it might likely be able to define the type of ObjC – but I can’t really infer that with the current snippet.

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

Sidebar

Related Questions

Let's say I have a class with a public property inside, like this: class
I have set a property across threads before and I found this post Cross-thread
In VB6, textboxes have their CausesValidation property set to True by default. In this
I have a class with a property that gets set by another class. Inside
I have a custom control that own a property. Inside this custom control OnInit
I have a c# object Person as a property inside another object Appointment. My
I have a class that needs a property set inside a LINQ-to-SQL query. My
I have set the AutoSize property of the form to True and I have
How can I have the property of a property set using NHibernate? Here is
I've got some Columns in a DataGridView that have their Binding property set to

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.