Counting the calls INTO my component?

R

Robert Hooker

I have this class, with 3 public methods:

MyAssembly.DLL
public MyClass
{
public void Method1() {;}
public void Method2() {;}
public void Method3() {;}

private void DetectCalls()
{

//See question below

}
}


I want the DetectCalls method to be able to:
1] Load an arbitrary assembly
2] Find all instances of code (in classes, or structs) in that assembly **
that make calls on any of Method1, Method2 or Method3 **

I see how I can load the assembly, and iterate thru all the types in that
assembly, but I stumped on the "check to see if any code in those types
calls MyClass in MyAssembly".

Is this possible? Can someone give me some pointers as to where to start
looking?
Cheers,
Rob
 
B

Ben Voigt

Robert Hooker said:
I have this class, with 3 public methods:

MyAssembly.DLL
public MyClass
{
public void Method1() {;}
public void Method2() {;}
public void Method3() {;}

private void DetectCalls()
{

//See question below

}
}


I want the DetectCalls method to be able to:
1] Load an arbitrary assembly
2] Find all instances of code (in classes, or structs) in that assembly
** that make calls on any of Method1, Method2 or Method3 **

I see how I can load the assembly, and iterate thru all the types in that
assembly, but I stumped on the "check to see if any code in those types
calls MyClass in MyAssembly".

Is this possible? Can someone give me some pointers as to where to start
looking?
Cheers,
Rob

..NET Reflector by Lutz Roeder does exactly that ("Analyzer" menu option),
and is extensible. Maybe you can do what you need by writing a plugin...
 
R

Robert Hooker

Thanks for the suggestion - but I need to do this in my own code...

Ben Voigt said:
Robert Hooker said:
I have this class, with 3 public methods:

MyAssembly.DLL
public MyClass
{
public void Method1() {;}
public void Method2() {;}
public void Method3() {;}

private void DetectCalls()
{

//See question below

}
}


I want the DetectCalls method to be able to:
1] Load an arbitrary assembly
2] Find all instances of code (in classes, or structs) in that assembly
** that make calls on any of Method1, Method2 or Method3 **

I see how I can load the assembly, and iterate thru all the types in that
assembly, but I stumped on the "check to see if any code in those types
calls MyClass in MyAssembly".

Is this possible? Can someone give me some pointers as to where to start
looking?
Cheers,
Rob

.NET Reflector by Lutz Roeder does exactly that ("Analyzer" menu option),
and is extensible. Maybe you can do what you need by writing a plugin...
 
G

Greg Young

You would have to analyze IL in order to do this.

This will not however be 100% reliable as someone could still be calling you
through reflections which you would not pick up. The mono project has some
open source libraries that make analyzing IL a breeze, but again this is not
going to be 100% reliable.

Cheers,

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top