Types.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Types.cs
  2. // (C) Sergey Chaban ([email protected])
  3. using System;
  4. using System.Collections;
  5. using System.Reflection;
  6. namespace Mono.ILASM {
  7. public class Types {
  8. // maps default types to their library equivalents
  9. private static Hashtable defaultTypes;
  10. private static readonly object dummy;
  11. private Hashtable userTypes;
  12. static Types ()
  13. {
  14. dummy = new Object ();
  15. defaultTypes = new Hashtable ();
  16. Hashtable t = defaultTypes;
  17. t ["object"] = Type.GetType ("System.Object");
  18. t ["string"] = Type.GetType ("System.String");
  19. t ["char"] = Type.GetType ("System.Char");
  20. t ["void"] = Type.GetType ("System.Void");
  21. t ["bool"] = Type.GetType ("System.Boolean");
  22. t ["int8"] = Type.GetType ("System.Byte");
  23. t ["int16"] = Type.GetType ("System.Int16");
  24. t ["int32"] = Type.GetType ("System.Int32");
  25. t ["int64"] = Type.GetType ("System.Int64");
  26. t ["float32"] = Type.GetType ("System.Single");
  27. t ["float64"] = Type.GetType ("System.Double");
  28. t ["uint8"] = Type.GetType ("System.SByte");
  29. t ["uint16"] = Type.GetType ("System.UInt16");
  30. t ["uint32"] = Type.GetType ("System.UInt32");
  31. t ["uint64"] = Type.GetType ("System.UInt64");
  32. }
  33. /// <summary>
  34. /// </summary>
  35. public Types ()
  36. {
  37. }
  38. /// <summary>
  39. /// </summary>
  40. /// <param name="typeName"></param>
  41. /// <returns></returns>
  42. public Type Lookup (string typeName)
  43. {
  44. Type res = defaultTypes [typeName] as Type;
  45. return res;
  46. }
  47. /// <summary>
  48. /// </summary>
  49. /// <param name="name"></param>
  50. /// <param name="type"></param>
  51. public void Add (string name, Type type)
  52. {
  53. if (defaultTypes.Contains (name)) return;
  54. if (userTypes == null) userTypes = new Hashtable ();
  55. userTypes [name] = (type != null) ? type : dummy;
  56. }
  57. /// <summary>
  58. /// </summary>
  59. /// <param name="name"></param>
  60. public void Add (string name){
  61. Add (name, null);
  62. }
  63. }
  64. }