Counting the calls INTO my component?

  • Thread starter Thread starter Robert Hooker
  • Start date Start date
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
 
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...
 
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...
 
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
 
Back
Top