Home All Groups Group Topic Archive Search About

Counting the calls INTO my component?

Author
24 May 2006 3:56 PM
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

Author
24 May 2006 11:27 PM
Ben Voigt
Show quote
"Robert Hooker" <rhooker@newsgroup.nospam> wrote in message
news:%23gWn1q0fGHA.764@TK2MSFTNGP05.phx.gbl...
>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...

Show quote
>
>
>
>
Author
25 May 2006 2:07 PM
Robert Hooker
Thanks for the suggestion - but I need to do this in my own code...

Show quote
"Ben Voigt" <rbv@nospam.nospam> wrote in message
news:%23taXSm4fGHA.2208@TK2MSFTNGP05.phx.gbl...
> "Robert Hooker" <rhooker@newsgroup.nospam> wrote in message
> news:%23gWn1q0fGHA.764@TK2MSFTNGP05.phx.gbl...
>>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...
>
>>
>>
>>
>>
>
>
Author
25 May 2006 5:00 PM
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
Show quote
"Robert Hooker" <rhooker@newsgroup.nospam> wrote in message
news:%23gWn1q0fGHA.764@TK2MSFTNGP05.phx.gbl...
>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
>
>
>
>

AddThis Social Bookmark Button