Re: [mono-cecil] MethodDefinition

120 views
Skip to first unread message

Jb Evain

unread,
Oct 7, 2012, 2:00:00 PM10/7/12
to mono-...@googlegroups.com
Hi,

I suspect there's an issue with your code.

Maybe you could post it here, to figure out what's wrong?

Jb

On Oct 5, 2012, at 1:41 AM, aixeiger wrote:

> Hi!
> here's my trouble when a try to read the methods in my class, i do foreach (MethodDefinition met in type.Methods) but this don't show me the methods in my classes why? and that class have one method, there are a other way to get the methods inside in a class?
>
> --
> --
> mono-cecil

aixeiger

unread,
Oct 18, 2012, 7:21:32 PM10/18/12
to mono-...@googlegroups.com
this is the code that i use for go through the methods

AssemblyDefinition asem = AssemblyFactory.GetAssembly(args[0]);
foreach (TypeDefinition tipo in asem.MainModule.Types)
{
    foreach (MethodDefinition met in tipo.Methods)
    {
           System.Console.WriteLine(met.Name);
    }
    foreach(PropertyDefinition pro in tipo.Properties)
    {
           System.Console.WriteLine(pro.Name);
    }
    foreach (FieldDefinition fie in tipo.Fields)
    {
            System.Console.WriteLine(fie.Name);
     }
            System.Console.WriteLine(tipo.FullName);
                    }


then when i run the application i get this



<Module>
Dispose
InitializeComponent
button1_Click
button2_Click
button3_Click
button4_Click
components
label1
button1
pictureBox1
button2
button3
button4
texta1
label2
pictureBox2
se
prop
Car.Form1
Dispose
InitializeComponent
button1_Click
components
label1
textBox1
button1
button2
button3
Car.Form2
get_Default
Default
defaultInstance
Car.Properties.Settings
carsettings
Car.Propiedades
get_ResourceManager
get_Culture
set_Culture
ResourceManager
Culture
resourceMan
resourceCulture
Car.Properties.Resources
Main
Car.Program
Car.Simulacion

that's are all the elements to my application but in the last two just show the name of the classes and my ask is how i can go through the methods inside the classes and propierties and to the access modifiers and the other things to this classes have

if you can help me please!

thanks!


Vidisha Ghosh

unread,
Oct 18, 2012, 7:37:20 PM10/18/12
to mono-...@googlegroups.com
You can traverse the nested types like this:

if(tipo.HasNestedTypes)   // where tipo is your type from the main foreach loop
{
  
foreach (TypeDefinition nestedType in tipo.NestedTypes)
{
        //do what you want to here..
}
}



--
--
mono-cecil



--
Vidisha Ghosh

aixeiger

unread,
Oct 18, 2012, 8:35:33 PM10/18/12
to mono-...@googlegroups.com
and i can get the name? for example:


namespace Car
{
    class Propiedades
    {
        public StringBuilder carsettings(int n)
        {
           //ahhh
        }
        public void carjobs()
        {
            // somethig
        }
    }
}

who i get the name of the namespace, the name of the class, and the name of the methods?

I apologize if not properly express!

deedee

unread,
Oct 22, 2012, 12:31:23 PM10/22/12
to mono-...@googlegroups.com
There is a Namespace and a FullName property associated with the type. You can fetch the value from there.

aixeiger

unread,
Oct 24, 2012, 12:18:19 PM10/24/12
to mono-...@googlegroups.com
Okay! then when i hace the name of a method how i can modified the metada, change the name for example to my method run change to opc! with mono cecil this can be do?
Message has been deleted

aixeiger

unread,
Oct 25, 2012, 9:12:51 PM10/25/12
to mono-...@googlegroups.com
thanks i find my mistake! if someone like add me to the skype to talk to mono cecil and programming c#! is :aixeiger thanks! cheers!
Reply all
Reply to author
Forward
0 new messages