PdbConstant.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //-----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft. All rights reserved.
  4. // This code is licensed under the Microsoft Public License.
  5. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  6. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  7. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  8. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  9. //
  10. //-----------------------------------------------------------------------------
  11. using System;
  12. using System.Runtime.InteropServices;
  13. namespace Microsoft.Cci.Pdb {
  14. internal class PdbConstant {
  15. internal string name;
  16. internal uint token;
  17. internal object value;
  18. internal PdbConstant(BitAccess bits) {
  19. bits.ReadUInt32(out this.token);
  20. byte tag1;
  21. bits.ReadUInt8(out tag1);
  22. byte tag2;
  23. bits.ReadUInt8(out tag2);
  24. if (tag2 == 0) {
  25. this.value = tag1;
  26. } else if (tag2 == 0x80) {
  27. switch (tag1) {
  28. case 0x00: //sbyte
  29. sbyte sb;
  30. bits.ReadInt8(out sb);
  31. this.value = sb;
  32. break;
  33. case 0x01: //short
  34. short s;
  35. bits.ReadInt16(out s);
  36. this.value = s;
  37. break;
  38. case 0x02: //ushort
  39. ushort us;
  40. bits.ReadUInt16(out us);
  41. this.value = us;
  42. break;
  43. case 0x03: //int
  44. int i;
  45. bits.ReadInt32(out i);
  46. this.value = i;
  47. break;
  48. case 0x04: //uint
  49. uint ui;
  50. bits.ReadUInt32(out ui);
  51. this.value = ui;
  52. break;
  53. case 0x05: //float
  54. this.value = bits.ReadFloat();
  55. break;
  56. case 0x06: //double
  57. this.value = bits.ReadDouble();
  58. break;
  59. case 0x09: //long
  60. long sl;
  61. bits.ReadInt64(out sl);
  62. this.value = sl;
  63. break;
  64. case 0x0a: //ulong
  65. ulong ul;
  66. bits.ReadUInt64(out ul);
  67. this.value = ul;
  68. break;
  69. case 0x10: //string
  70. string str;
  71. bits.ReadBString(out str);
  72. this.value = str;
  73. break;
  74. case 0x19: //decimal
  75. this.value = bits.ReadDecimal();
  76. break;
  77. default:
  78. //TODO: error
  79. break;
  80. }
  81. } else {
  82. //TODO: error
  83. }
  84. bits.ReadCString(out name);
  85. }
  86. }
  87. }