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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:55:31+00:00 2026-05-11T09:55:31+00:00

For pupose of explaining let’s say that I have a Company object which has

  • 0

For pupose of explaining let’s say that I have a Company object which has an Address property of type Address. so it would be something like:

 public class Company   {       Address CompanyAddress; }    public class Address   {     int Number;     string StreetName;   } 

Now I have a method that works with any kind of object type and I want to get a specific property from the received object, so I’m trying the following:

 public string MyMethod(object myObject, string propertyName) {     Type objectType = myObject.GetType();     object internalObject = objectType.GetProperty('Address');      Type internalType = internalObject.GetType();     PropertyInfo singleProperty = internalType.GetProperty('StreetName');      return singleProperty.GetValue(internalObject, null).ToString(); } 

The problem is that internalType is never Address but ‘System.Reflection.RuntimePropertyInfo’ so singleProperty is always null;

How can I accomplish this?

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. 2026-05-11T09:55:32+00:00Added an answer on May 11, 2026 at 9:55 am

    The problem with your code is that internalObject will be the PropertyInfo object returned by GetProperty method. You need to get the actual value of that property, hence the call to GetValue method.

    public string MyMethod(object myObject, string propertyName) {     Type objectType = myObject.GetType();     object internalObject = objectType.GetProperty('Address').GetValue(myObject, null);      Type internalType = internalObject.GetType();     PropertyInfo singleProperty = internalType.GetProperty('StreetName');      return singleProperty.GetValue(internalObject, null).ToString();  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess this question that would have already been asked here. I searched but
First let me start by explaining my use case: Say there is a database
I have a windows application and I require that the user logins in the
Novice Programmer here - I have an application with two threads that I start,
i heard someone say that the purpose of scripting languages it to abastract out
Let me begin by explaining what I'm trying to accomplish. Essentially there are two
I have a service that I had to log on to the local admin
One recommends me the following code apparently only in .zshrc without explaining its purpose
The purpose I aming for is, that 2 seconds after my activity was started
My purpose is user enter only email or mobile number. I have the partial

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.