Reflection with static inherited methods
-
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
-
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
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.
-
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.
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
-
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
-
You can't. Static methods only exist in the class where they are declared. They are not inherited. --- b { font-weight: normal; }