There is an asp.net webpage. Inside Page_Load
event there could be multiple method calls ( MethodA
, MethodB(arg1, arg2)
etc.)
I have httpmodule. While accessing the page, it will first go thorough httpmodule.
Inside that hpttpmodule, I want to find or list all methods which are being called in current executing page's Page_Load
.
By this way, I want to make sure that a particular method ( MethodA
) with its signature is implemented inside Page_Load
event.
I will appreciate any implementation, weather httpmodule, base page, abstract class, interfaces, reflection etc... anything to achieve this objective.
Thanks
You could try something like this :
MethodBase methodBase = typeof(INSERT_CLASS_HERE).GetMethod(INSERT_METHOD_HERE);
var instructions = MethodBodyReader.GetInstructions(methodBase);
foreach (Instruction instruction in instructions)
{
MethodInfo methodInfo = instruction.Operand as MethodInfo;
if(methodInfo != null)
{
Type type = methodInfo.DeclaringType;
ParameterInfo[] parameters = methodInfo.GetParameters();
Console.WriteLine("{0}.{1}({2});",
type.FullName,
methodInfo.Name,
String.Join(", ", parameters.Select(p => p.ParameterType.FullName + " " + p.Name).ToArray())
);
}
}
Where INSERT_CLASS_HERE
is the name of the class where you want to look.
And INSERT_METHOD_HERE
is the name of the method within the class in which you want to find all calls.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.