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. Reflection with static inherited methods

Reflection with static inherited methods

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 4 Posters 0 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.
  • O Offline
    O Offline
    osamahmirza
    wrote on last edited by
    #1

    Hi, I am trying to invoke a static method on "a_class" which is derived by "another_class" and the static function I am trying to invoke in "another_class". The problem is that I am trying to do this by using reflections. And by using reflections on "a_class" I can not see any MethodInfo for any static method declared in "another_class". I am trying to do something as follows: //I will be getting a generic collection in this object object oCollection; //Getting the type Type factoryType = BuildManager.GetType("My.NameSpace.Class", true); //Calling a static function on factoryType oCollection = factoryType.InvokeMember("GetByFilter", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy, null, null, new object[] { }); Can anybody kindly tell me how can I achive this? Thanks in advance Stuck

    J G 2 Replies Last reply
    0
    • O osamahmirza

      Hi, I am trying to invoke a static method on "a_class" which is derived by "another_class" and the static function I am trying to invoke in "another_class". The problem is that I am trying to do this by using reflections. And by using reflections on "a_class" I can not see any MethodInfo for any static method declared in "another_class". I am trying to do something as follows: //I will be getting a generic collection in this object object oCollection; //Getting the type Type factoryType = BuildManager.GetType("My.NameSpace.Class", true); //Calling a static function on factoryType oCollection = factoryType.InvokeMember("GetByFilter", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy, null, null, new object[] { }); Can anybody kindly tell me how can I achive this? Thanks in advance Stuck

      J Offline
      J Offline
      Josh Smith
      wrote on last edited by
      #2

      I think that getting rid of the DeclaredOnly binding flag should do the trick (assuming that factoryType == typeof(a_class)). DeclaredOnly specifies that the search should not look in base classes for the member.

      G 1 Reply Last reply
      0
      • J Josh Smith

        I think that getting rid of the DeclaredOnly binding flag should do the trick (assuming that factoryType == typeof(a_class)). DeclaredOnly specifies that the search should not look in base classes for the member.

        G Offline
        G Offline
        guroo13
        wrote on last edited by
        #3

        Hi Josh, I really appriciate that you answered my question. I tried by taking off DeclaredOnly BindingFlag but it still didnt work. Any other suggestion? By the way, I was able to see the methods declared public in parent class, but I was not able to see the public static method declared in parent class. Thank you

        1 Reply Last reply
        0
        • O osamahmirza

          Hi, I am trying to invoke a static method on "a_class" which is derived by "another_class" and the static function I am trying to invoke in "another_class". The problem is that I am trying to do this by using reflections. And by using reflections on "a_class" I can not see any MethodInfo for any static method declared in "another_class". I am trying to do something as follows: //I will be getting a generic collection in this object object oCollection; //Getting the type Type factoryType = BuildManager.GetType("My.NameSpace.Class", true); //Calling a static function on factoryType oCollection = factoryType.InvokeMember("GetByFilter", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy, null, null, new object[] { }); Can anybody kindly tell me how can I achive this? Thanks in advance Stuck

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          You can't. Static methods only exist in the class where they are declared. They are not inherited. --- b { font-weight: normal; }

          G 1 Reply Last reply
          0
          • G Guffa

            You can't. Static methods only exist in the class where they are declared. They are not inherited. --- b { font-weight: normal; }

            G Offline
            G Offline
            guroo13
            wrote on last edited by
            #5

            Thanks alot Guffa for answering!! seems like I am out of luck :(

            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