Invoke Private method of inherited class
-
Hi, I have created a custom grid class which inherits from the DataGrid class. Using reflection i want to invoke on of the private method of the base class. Am able to list all the public method, but not able to get the refernce to the private methods. Attached is the class am using.
public class CustomDataGridTest : DataGrid { private DataTable PopulateTable() { DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Rows.Add(new object[] {"John"}); dt.Rows.Add(new object[] {"Miller"}); dt.Rows.Add(new object[] {"Lara"}); dt.Rows.Add(new object[] {"Tommy"}); dt.Rows.Add(new object[] {"Robin"}); return dt; } public MethodInfo GetMethodInfo() { this.DataSource = PopulateTable(); **MethodInfo mi = base.GetType().GetMethod**("get_DataGridRows", BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); return mi; } }
Can anyone tell me as why the GetType().GetMethod() not returning the methodinfo object. It always return null. Thanks in advance for any kind of help Regards, Kais -
Hi, I have created a custom grid class which inherits from the DataGrid class. Using reflection i want to invoke on of the private method of the base class. Am able to list all the public method, but not able to get the refernce to the private methods. Attached is the class am using.
public class CustomDataGridTest : DataGrid { private DataTable PopulateTable() { DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Rows.Add(new object[] {"John"}); dt.Rows.Add(new object[] {"Miller"}); dt.Rows.Add(new object[] {"Lara"}); dt.Rows.Add(new object[] {"Tommy"}); dt.Rows.Add(new object[] {"Robin"}); return dt; } public MethodInfo GetMethodInfo() { this.DataSource = PopulateTable(); **MethodInfo mi = base.GetType().GetMethod**("get_DataGridRows", BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); return mi; } }
Can anyone tell me as why the GetType().GetMethod() not returning the methodinfo object. It always return null. Thanks in advance for any kind of help Regards, KaisBecause you have to use GetProperty() method to retrieve a property. Best regards, ----------- Igor Sukhovhttp://sukhov.net
-
Because you have to use GetProperty() method to retrieve a property. Best regards, ----------- Igor Sukhovhttp://sukhov.net
-
Igor, I dont see any such property to reterive the get datagrid rows collection. Is there any alternate way to reterive that. Regards, Kais
First, what is the type of your datagrid ? Are you absolutely sure that this particular datagrid class have a method with the "get_DataGridRows" name ? Best regards, ----------- Igor Sukhovhttp://sukhov.net
-
First, what is the type of your datagrid ? Are you absolutely sure that this particular datagrid class have a method with the "get_DataGridRows" name ? Best regards, ----------- Igor Sukhovhttp://sukhov.net
Hi , Am using windows form datagrid. The datagrid class has a private method named get_DataGridRows. This method will hold the DataRow collection of the datagrid. Since am inheriting the Datagrid class am not able to access this method. If i use it directly am able to access it. Regards, Kais
-
Hi , Am using windows form datagrid. The datagrid class has a private method named get_DataGridRows. This method will hold the DataRow collection of the datagrid. Since am inheriting the Datagrid class am not able to access this method. If i use it directly am able to access it. Regards, Kais
Windows Forms datagrid do have internal DataGridRows property and get_DataGridRows method is the get accessor for this property. It's recomended to retrieve property value by obtaining a PropertyInfo object first and calling GetValue method on that object. Best regards, ----------- Igor Sukhovhttp://sukhov.net