/symbols/pdb/Microsoft.Cci.Pdb/PdbConstant.cs

http://github.com/jbevain/cecil · C# · 89 lines · 80 code · 4 blank · 5 comment · 7 complexity · 9a10903ee5353ddd67c276d04e2b663e MD5 · raw file

  1. // Copyright (c) Microsoft. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using System;
  4. using System.Runtime.InteropServices;
  5. namespace Microsoft.Cci.Pdb {
  6. /// <summary />
  7. internal class PdbConstant {
  8. internal string name;
  9. internal uint token;
  10. internal object value;
  11. internal PdbConstant(string name, uint token, object value) {
  12. this.name = name;
  13. this.token = token;
  14. this.value = value;
  15. }
  16. internal PdbConstant(BitAccess bits) {
  17. bits.ReadUInt32(out this.token);
  18. byte tag1;
  19. bits.ReadUInt8(out tag1);
  20. byte tag2;
  21. bits.ReadUInt8(out tag2);
  22. if (tag2 == 0) {
  23. this.value = tag1;
  24. } else if (tag2 == 0x80) {
  25. switch (tag1) {
  26. case 0x00: //sbyte
  27. sbyte sb;
  28. bits.ReadInt8(out sb);
  29. this.value = sb;
  30. break;
  31. case 0x01: //short
  32. short s;
  33. bits.ReadInt16(out s);
  34. this.value = s;
  35. break;
  36. case 0x02: //ushort
  37. ushort us;
  38. bits.ReadUInt16(out us);
  39. this.value = us;
  40. break;
  41. case 0x03: //int
  42. int i;
  43. bits.ReadInt32(out i);
  44. this.value = i;
  45. break;
  46. case 0x04: //uint
  47. uint ui;
  48. bits.ReadUInt32(out ui);
  49. this.value = ui;
  50. break;
  51. case 0x05: //float
  52. this.value = bits.ReadFloat();
  53. break;
  54. case 0x06: //double
  55. this.value = bits.ReadDouble();
  56. break;
  57. case 0x09: //long
  58. long sl;
  59. bits.ReadInt64(out sl);
  60. this.value = sl;
  61. break;
  62. case 0x0a: //ulong
  63. ulong ul;
  64. bits.ReadUInt64(out ul);
  65. this.value = ul;
  66. break;
  67. case 0x10: //string
  68. string str;
  69. bits.ReadBString(out str);
  70. this.value = str;
  71. break;
  72. case 0x19: //decimal
  73. this.value = bits.ReadDecimal();
  74. break;
  75. default:
  76. //TODO: error
  77. break;
  78. }
  79. } else {
  80. //TODO: error
  81. }
  82. bits.ReadCString(out name);
  83. }
  84. }
  85. }