Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get class that method was defined in?

Given a MethodInfo object, how can I get the Type object for the class that it was defined in?

like image 899
mpen Avatar asked Jan 01 '11 23:01

mpen


People also ask

How do I know what class a method is in Python?

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.

What is the __ call __ method?

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.

What does the __ Add__ method do?

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.


2 Answers

You're looking for the DeclaringType property:

Gets the class that declares this member.

like image 126
LukeH Avatar answered Oct 02 '22 23:10

LukeH


You can get the Type the method belongs to with the DeclaringType property

like image 30
nos Avatar answered Oct 02 '22 23:10

nos