Given a MethodInfo
object, how can I get the Type
object for the class that it was defined in?
To list the methods for this class, one approach is to use the dir() function in Python. The dir() function will return all functions and properties of the class.
Python has a set of built-in methods and __call__ is one of them. The __call__ method enables Python programmers to write classes where the instances behave like functions and can be called like a function.
The __add__() method in Python specifies what happens when you call + on two objects. When you call obj1 + obj2, you are essentially calling obj1. __add__(obj2). This works, because int implements the __add__() method behind the scenes.
You're looking for the DeclaringType
property:
Gets the class that declares this member.
You can get the Type the method belongs to with the DeclaringType property
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With