/dbg/Program.cs

http://github.com/jbevain/cecil · C# · 60 lines · 42 code · 14 blank · 4 comment · 0 complexity · d6a6e6e17c7efe804028c1e6f628a8c8 MD5 · raw file

  1. using System;
  2. using System.IO;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using Mono.Cecil.Mdb;
  6. namespace Mono.Cecil.Debug {
  7. interface IFoo { }
  8. interface IBar : IFoo { }
  9. abstract class Bar : IBar { }
  10. delegate void Action ();
  11. class Program {
  12. static int Answer ()
  13. {
  14. return 42;
  15. }
  16. static void Main (string [] args)
  17. {
  18. Time (() => {
  19. var module = GetCurrentModule ();
  20. module.Write ("dbg.rt.exe");
  21. });
  22. }
  23. static void Time (Action action)
  24. {
  25. var watch = new Stopwatch ();
  26. watch.Start ();
  27. action ();
  28. watch.Stop ();
  29. Console.WriteLine ("Elapsed: {0}", watch.Elapsed);
  30. }
  31. //static TypeDefinition GetCurrentType ()
  32. //{
  33. // return GetCurrentModule ().Types [typeof (Program).FullName];
  34. //}
  35. static ModuleDefinition GetModule (string module)
  36. {
  37. return ModuleDefinition.ReadModule (module, new ReaderParameters {
  38. ReadingMode = ReadingMode.Deferred,
  39. });
  40. }
  41. static ModuleDefinition GetCurrentModule ()
  42. {
  43. return GetModule (typeof (object).Module.FullyQualifiedName);
  44. }
  45. }
  46. }