LocalBuilder.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // System.Reflection.Emit/LocalBuilder.cs
  3. //
  4. // Authors:
  5. // Paolo Molaro ([email protected])
  6. // Martin Baulig ([email protected])
  7. // Miguel de Icaza ([email protected])
  8. //
  9. // (C) 2001, 2002 Ximian, Inc. http://www.ximian.com
  10. //
  11. using System;
  12. using System.Reflection;
  13. using System.Reflection.Emit;
  14. using System.Globalization;
  15. using System.Runtime.CompilerServices;
  16. using System.Diagnostics.SymbolStore;
  17. namespace System.Reflection.Emit {
  18. public sealed class LocalBuilder {
  19. //
  20. // These are kept in sync with reflection.h
  21. //
  22. #region Sync with reflection.h
  23. private Type type;
  24. private string name;
  25. #endregion
  26. //
  27. // Order does not matter after here
  28. //
  29. internal uint position;
  30. internal ILGenerator ilgen;
  31. internal LocalBuilder (Type t, ILGenerator ilgen)
  32. {
  33. this.type = t;
  34. this.ilgen = ilgen;
  35. }
  36. public void SetLocalSymInfo (string lname, int startOffset, int endOffset)
  37. {
  38. this.name = lname;
  39. SignatureHelper sighelper = SignatureHelper.GetLocalVarSigHelper (ilgen.module);
  40. sighelper.AddArgument (type);
  41. byte[] signature = sighelper.GetSignature ();
  42. ilgen.sym_writer.DefineLocalVariable (lname, FieldAttributes.Private,
  43. signature, SymAddressKind.ILOffset,
  44. (int) position, 0, 0,
  45. startOffset, endOffset);
  46. }
  47. public void SetLocalSymInfo (string lname)
  48. {
  49. SetLocalSymInfo (lname, 0, 0);
  50. }
  51. public Type LocalType
  52. {
  53. get {
  54. return type;
  55. }
  56. }
  57. }
  58. }