Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Invoke Private method of inherited class

Invoke Private method of inherited class

Scheduled Pinned Locked Moved C#
csshelp
6 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kais4U
    wrote on last edited by
    #1

    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

    I 1 Reply Last reply
    0
    • K Kais4U

      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

      I Offline
      I Offline
      Igor Sukhov
      wrote on last edited by
      #2

      Because you have to use GetProperty() method to retrieve a property. Best regards, ----------- Igor Sukhovhttp://sukhov.net

      K 1 Reply Last reply
      0
      • I Igor Sukhov

        Because you have to use GetProperty() method to retrieve a property. Best regards, ----------- Igor Sukhovhttp://sukhov.net

        K Offline
        K Offline
        Kais4U
        wrote on last edited by
        #3

        Igor, I dont see any such property to reterive the get datagrid rows collection. Is there any alternate way to reterive that. Regards, Kais

        I 1 Reply Last reply
        0
        • K Kais4U

          Igor, I dont see any such property to reterive the get datagrid rows collection. Is there any alternate way to reterive that. Regards, Kais

          I Offline
          I Offline
          Igor Sukhov
          wrote on last edited by
          #4

          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

          K 1 Reply Last reply
          0
          • I Igor Sukhov

            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

            K Offline
            K Offline
            Kais4U
            wrote on last edited by
            #5

            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

            I 1 Reply Last reply
            0
            • K Kais4U

              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

              I Offline
              I Offline
              Igor Sukhov
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups