0

我对 GetProperty 有疑问

partial class MyForm : Form
{
    ...

    public System.Windows.Forms.BindingSource authorBindingSource = new ...;
    public MethodicalWorkDataSetTableAdapters.authorTableAdapter authorTableAdapter = new ...;

    ...


    public static object GetPropValue(object src, string propName)
    {
        return src.GetType().GetProperty(propName).GetValue(src, null);
    }

    public void someFunction()
    {
        GetPropValue( this, "authorBindingSource" ); // returns null
    }
}

请帮助我,函数 GetPropValue 工作正常,除了“authorTableAdapter”和“authorBindingSource”

4

2 回答 2

0

在您的示例中,authorTableAdapterandauthorBindingSourcefields,而不是properties。更改GetPropertyGetField

于 2014-04-15T15:00:26.433 回答
0

使用GetMember而不是GetProperty

于 2014-04-15T15:00:38.267 回答