Hi,

I already answered on SO:

http://stackoverflow.com/questions/4272138/cil-instructions-check-if-a-getter-method-is-called/4272322#4272322

On Wed, Nov 24, 2010 at 11:41 PM, Sebastian Müller
<[email protected]> wrote:
> Hi together
>
> To calculate a code metric (ATFD - Access to Foreign Data), I'd like to
> check which getter methods in other classes are called by the class I
> measure. I know how to list all methods that are called by another method,
> but how can I check if the method is a getter method? And how do I check
> which field is returned in the getter method?
>
> I was able to do it for fields that are directly accessed (syntax may be
> little bit different than in MonoCecil since i used DrivenMetrics) but now
> I'd like to do it also for getter methods:
>
> foreach (MethodDefinition method in type.Methods)
>             {
>                 foreach (Instruction instruction in
> method.Body.Instructions)
>                 {
>
>                     if (instruction.OpCode == OpCodes.Ldfld)
>                     {
>                         FieldReference field = instruction.Operand as
> FieldReference;
>
>
>
>                         if (fields.Contains(field.ToString()) &&
> !accesses.Contains(field.ToString()))
>                         {
>                             accesses.Add(field.ToString());
>                             Console.WriteLine("Class " + type.Name + "
> accesses field " + field.Name + " of a foreign class.");
>                         }
>
>                     }
>                 }
>             }
>
> Thanks for any hints!
>
> --
> --
> mono-cecil

-- 
--
mono-cecil

Reply via email to