Advertisement
LaPanthere

Tutorial 1: Iterating, loading and saving

Jan 31st, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Mono.Cecil;
  6.  
  7. namespace Tutorial1Code
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // Loads the assembly from the start arguments
  14.             AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(args[0]);
  15.            
  16.             // Iterates through the assembly's modules, aspects of the program
  17.             foreach (ModuleDefinition mod in asm.Modules)
  18.             {
  19.                 // Iterates through the classes of the assembly
  20.                 foreach (TypeDefinition td in mod.Types)
  21.                 {
  22.                     // Writes the types name,
  23.                     DoType(td);
  24.                 }
  25.             }
  26.             Console.ReadLine();
  27.         }
  28.         static void DoType(TypeDefinition td)
  29.         {
  30.             foreach (TypeDefinition ntd in td.NestedTypes)
  31.             {
  32.                 // Repeat if the class has nested classes.
  33.                 DoType(ntd);
  34.             }
  35.             foreach (MethodDefinition md in td.Methods)
  36.             {
  37.                 // Log the content to the console
  38.                 Log(td.Name + " > " + md.Name);
  39.             }
  40.         }
  41.         static void Log(string text)
  42.         {
  43.             Console.WriteLine(text);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement