You don't have any direct type references in your test application.
If you check the IL, you'll notice that it looks something like this:

newobj void Class1::.ctor(void)
call string Class1::Test(void)
call System.Console.WriteLine(string)

All the operands are method references.
However, consider the following:

ldnull
castclass Class1
pop

Here the operand of the 'castclass' instruction is a TypeReference.

Hope it's clear now.

2011/6/18 Alex B <[email protected]>

> Hellow, JB.
>
> Try your advice (http://groups.google.com/group/mono-cecil/
> browse_thread/thread/dfb05686e35cbcad/981d606149de1e99?
> lnk=gst&q=used#981d606149de1e99)
>
> >Just iterate over the instructions in the body of MyMethod. Switch on
> >the opcode of the instruction, if its OperandType is InlineType, the
> >operand of the Instruction will be a TypeReference.
>
> This is test application:
>
> namespace ConsoleApplication1
> {
>    class Program
>    {
>        static void Main(string[] args)
>        {
>            Class1 cl = new Class1();
>            Console.WriteLine(cl.Test());
>        }
>    }
> }
>
> Now I try to get all types in Main method:
>
> var module = ModuleDefinition.ReadModule(fileName);
> var type = module.Types.First(tt => tt.FullName ==
> "ConsoleApplication1.Program");
> var method = type.Methods.First(mm => mm.FullName == "System.Void
> ConsoleApplication1.Program::Main(System.String[])");
>
> foreach (var instruction in method.Body.Instructions)
> {
>    if (instruction.OpCode.OperandType == OperandType.InlineType)
>    {
>        Console.WriteLine(instruction);
>    }
> }
>
> There are no instruction.OpCode.OperandType == OperandType.InlineType
> What I do wrong?
> The main task is to get all types used in assembly.
>
>
> On 17 июн, 22:57, Jb Evain <[email protected]> wrote:
> > Hi,
> >
> > On Fri, Jun 17, 2011 at 7:59 PM, Alex B <[email protected]> wrote:
> > > Is there a way to get all types used inside C# method ie:
> >
> > > public int foo(string str)
> > > {
> > >  Bar bar = new Bar();
> > >  string x = "test";
> > >  TEST t = bar.GetTEST();
> > > }
> >
> > There's no builtin way. See for instance:
> >
> > http://groups.google.com/group/mono-cecil/browse_thread/thread/dfb056...
> >
> > Jb
>
> --
> --
> mono-cecil

-- 
--
mono-cecil

Reply via email to