TypeDescriptor.GetProperties return nothing from a class

I have defined a class TestObject that contains two simple properties num and name. I am trying to use TypeDescriptor.GetProperties() for the object of TestObject class to retrieve the defined properties. But, it doesn't return anything.

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        object selobj = new TestObject();

        foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(selobj))
        {
            string cat = pd.Category;
        }
    }
}


public class TestObject
{
    string name = "Hello World";

    int Num
    {
        get { return 100; }
    }

    string Name
    {
        get { return name; }
        set { name = value; }
    }
}

Am I missing something simple here? Appreciate your help.

Answers


Make sure the properties are marked as public


Need Your Help

In a stored procedure, it it better to simply query data or to construct a query and then execute it? why?

sql sql-server stored-procedures

I have worked on SQL stored procedures and I have noticed that many people use two different approaches -

How to expand 2 textboxes (out of three) equally when one of them is collapsed?

wpf layout width

I have three textboxes...inside a stack panel (orientation = Horizontal).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.