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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:08:32+00:00 2026-05-22T00:08:32+00:00

Sometimes I want to know if an object has a property that I am

  • 0

Sometimes I want to know if an object has a property that I am looking for but sometimes an object has a lot of properties and it may take some time to find it debugging it. It will be nice if I could write a function that will find all the properties and its values in a a string then I can paste that string in notepad for instance and look for the value that I am looking for with the find feature that notepad has. So far I have something like this:

public void getAllPropertiesAndSubProperties(System.Reflection.PropertyInfo[] properties)
        {
            foreach (var a in properties)
            {
                //MessageBox.Show(a.ToString());
                // do something here to test if property a is the one 
                // I am looking for
                System.Reflection.PropertyInfo[] temp = a.GetType().GetProperties();
                // if property a has properties then call the function again
                if (temp.Length > 0) getAllPropertiesAndSubProperties(temp);
            }
        }

Editing the question I have worked:

so far I have added the following code. I can pass whatever object I want to the following method and I can see all the properties. I am having trouble viewing the values of the properties

![public void stackOverex(dynamic obj)
{
    // this is the string where I am apending all properties
    string stringProperties = "";

    Type t = obj.GetType();
    List<PropertyInfo> l = new List<PropertyInfo>();
    while (t != typeof(object))
    {
        l.AddRange(t.GetProperties());
        t = t.BaseType;

        var properites = t.GetType().GetProperties();
        foreach (var p in properites)
        {
            string val = "";
            try
            {
                val = obj.GetType().GetProperty(p.Name).GetValue(obj, null).ToString();
            }
            catch
            {

            }
            stringProperties += p.Name + " - " + val + "\r\n";
        }

    }

    MessageBox.Show(stringProperties);
}

enter image description here

Yeah visual studio debugger is great but look how many properties an object can have. I am actually looking for the indexSomething property of a gridViewColumnHeader I don’t remember the exact name I just remember I have used it before. I have an event that fires when a column gets clicked and I would like to know the index not the name “column number 2? or 3 was clicked”. I know I can get it with the name but it will be nice if I can implement this debugger function. See how complex it can get in the picture below.

enter image description here

  • 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-22T00:08:33+00:00Added an answer on May 22, 2026 at 12:08 am

    If you want all properties including of base type then you could do this:

            Type t = typeof(AnyType);
            List<PropertyInfo> l = new List<PropertyInfo>();
            while (t != typeof(object))
            {
                l.AddRange(t.GetProperties());
                t = t.BaseType;
            }
    

    or maybe you want a recursive print of properties, up to a level:

        public static void ReadALotOfValues(StringBuilder b, object o, int lvl, int maxLvl)
        {
            Type t = o.GetType();
            List<PropertyInfo> l = new List<PropertyInfo>();
            while (t != typeof(object))
            {
                l.AddRange(t.GetProperties());
                t = t.BaseType;
            }
            foreach (var item in l)
            {
                if (item.CanRead && item.GetIndexParameters().Length == 0)
                {
                    object child = item.GetValue(o, null);
                    b.AppendFormat("{0}{1} = {2}\n", new string(' ', 4 * lvl), item.Name, child);
                    if (lvl < maxLvl)
                        ReadALotOfValues(b, child, lvl + 1, maxLvl);
    
                }
            }
        }
    

    EDIT: Calling the above method:

    object o = ...some object here...;
    var b = new StringBuilder();
    ReadALotOfValues(b, o, 0, 5);
    Console.WriteLine(b.ToString());
    

    The above will read properties of up to 5 levels of depth into the objeto.

    The search must be limited somehow, otherwise it would loop forever… think of a self-referencing object.

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

Sidebar

Related Questions

I know that Java have its own garbage collection, but sometimes I want to
Sometimes I want to return the value that is a property of an object
I know that you can mark a scala object as @serializable , but I
I want to know what the best practice is for passing values (sometimes multiple
If I'm not online, I sometimes want to package some changes to a commit,
Sometimes I want to build Python or GCC from scratch just for fun, but
Windows's Snipping tool can capture the screen, but sometimes I want to capture the
I found a blog entry which suggests that sometimes c# compiler may decide to
This has been bugging me for some time now. My problem is the following.
I want to now if can JPQL retrieve the composed object. ObjectA has ObjectB

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.