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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:09:47+00:00 2026-06-05T18:09:47+00:00

I am recrusively evaluating properties via reflection using object.GetType().GetProperty(string propertyName). This is working fine

  • 0

I am recrusively evaluating properties via reflection using object.GetType().GetProperty(string propertyName).

This is working fine in case the obj is of sealed class but having property as an object of normal public class. However if this property contains a sealed class object, it doesnt return any property via GetProperty() method.

Trying to iterate recursively from Baseclass object via Prpty1 –>Prpty2–>Prpty3. param.Properties contains string array for Prpty1 ,Prpty2,Prpty3. Am not able to get Prpty2, it is coming as Null. Using the methods written below for this access.

Sample Code is as follows:

//Methods below are used to extract value from Object (basically BaseClass Object)

 private string EvaluateObject(object obj, MappedParameter param)
    {
        object evaluatedObj = obj;
        foreach (string s in param.Properties)
        {
            evaluatedObj = EvalProperty(evaluatedObj, s);
        }
        return (evaluatedObj == obj ? null : evaluatedObj.ToString());
    }

    private object EvalProperty(object obj, string propertyName)
    {
        System.Reflection.PropertyInfo propInfo = obj.GetType().GetProperty(propertyName);
        if (propInfo == null)
            throw new Exception("Invalid Property token");
        object propertyValue = propInfo.GetValue(obj, null);
        return propertyValue;
    }


//Below classes are Data Wrappers

 namespace TryClassLibrary
 {
 public class BaseClass
 {
    private NestedClass _Data = new NestedClass();    

    public NestedClass Prpty1
    {
        set { _Data = value; }
        get { return _Data; }
    }
}
}

 namespace TryClassLibrary
{
public sealed class NestedClass
{
    public int Id { get; set; }

    public NestedNestedClass Prpty2 = new NestedNestedClass();
}

public sealed class NestedNestedClass
{
    private string _Message;

    public NestedNestedClass()
    {
        Prpty3 = "Test value";
    }

    public string Prpty3
    {
        set
        {
            _Message = value;
        }
        get { return _Message; }
    }
}
}

Please can somebody help me finding the way to access Prpty2, Prpty3 or is it some existing constraint in using reflection. Thanks.

  • 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-05T18:09:49+00:00Added an answer on June 5, 2026 at 6:09 pm

    Ah, the problem is simple: Prpty2 is not a property: it is a field:

    public NestedNestedClass Prpty2 = new NestedNestedClass();
    

    should be:

    private readonly NestedNestedClass prpty2 = new NestedNestedClass();
    public NestedNestedClass Prpty2 { get { return prpty2; } }
    

    (or similar)

    Then it all works:

    object obj = new BaseClass();
    obj = obj.GetType().GetProperty("Prpty1").GetValue(obj, null);
    obj = obj.GetType().GetProperty("Prpty2").GetValue(obj, null);
    obj = obj.GetType().GetProperty("Prpty3").GetValue(obj, null);
    string s = obj.ToString(); // "Test value"
    

    For info, if you are doing lots of this – maybe look at FastMember; it is more convenient, and heavily optimised so to not pay the reflection tax.

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

Sidebar

Related Questions

I am using this class for porting array to XML: class ArrayToXML { /**
I need to recursively copy a directory (C:\test in this case) to a remote
Following this questionn Recursively rename files using find and sed I found by myself
How can I recursively get all the properties of an object only if the
I'm trying to recursively get some data using connect by, which for each row
How can I recursively count files in a Linux directory? I found this: find
I am working on an interpreter for a toy language, just to learn about
This recursive definition of a macro does what it should (sum integers from 1
How do I (recursively) search all file contents in Windows 7? I am using
I have a recursively defined user control that needs the following properties: there are

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.