0

i have problem with 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
    }
}

Please help me, function GetPropValue works fine, except "authorTableAdapter" and "authorBindingSource "

Madyuskin
  • 3
  • 2

2 Answers2

0

In your example, authorTableAdapter and authorBindingSource are fields, not properties. Change GetProperty to GetField.

Michael Gunter
  • 12,528
  • 1
  • 24
  • 58
0

use GetMember instead of GetProperty

yazan
  • 600
  • 7
  • 12