Domanda

Ho definito una TestObject classe che contiene due proprietà semplici num e il nome. Sto cercando di utilizzare TypeDescriptor.GetProperties () per l'oggetto della classe TestObject per recuperare le proprietà definite. Ma, non restituisce nulla.

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; }
    }
}

mi manca qualcosa di semplice qui? Apprezzare il vostro aiuto.

È stato utile?

Soluzione

Assicurarsi che le proprietà sono contrassegnati come pubblico

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top