OperatingSystem.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //------------------------------------------------------------------------------
  2. //
  3. // System.Environment.cs
  4. //
  5. // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
  6. //
  7. // Author: Jim Richardson, [email protected]
  8. // Created: Saturday, August 11, 2001
  9. //
  10. //------------------------------------------------------------------------------
  11. using System;
  12. namespace Mono.System
  13. {
  14. // this seemed like a logical place to put this enumeration
  15. public enum PlatformID
  16. { // TODO: determine what definitions to incorporate
  17. // possibilities are quite varied
  18. minPlatform,
  19. i386Linux = minPlatform,
  20. i686Linux,
  21. maxPlatform
  22. }
  23. /// <summary>
  24. /// Class representing a specific operating system version for a specific platform
  25. /// </summary>
  26. public sealed class OperatingSystem : ICloneable
  27. {
  28. private PlatformID itsPlatform;
  29. private Version itsVersion;
  30. public OperatingSystem(PlatformID platform, Version version)
  31. {
  32. if(version == null)
  33. {
  34. throw new ArgumentNullException();
  35. }
  36. // the doc doesn't say this, but I would
  37. //if(platform < minPlatform || platform >= maxPlatform)
  38. //{
  39. // throw new ArgumentOutOfRangeException();
  40. // TODO: find out if C# has assertion mechanism
  41. // isn't learning new languages fun? :)
  42. //}
  43. itsPlatform = platform;
  44. itsVersion = version;
  45. }
  46. /// <summary>
  47. /// Get the PlatformID
  48. /// </summary>
  49. public PlatformID Platform
  50. {
  51. get
  52. {
  53. return itsPlatform;
  54. }
  55. }
  56. /// <summary>
  57. /// Gets the version object
  58. /// </summary>
  59. public Version Version
  60. {
  61. get
  62. {
  63. return itsVersion;
  64. }
  65. }
  66. /// <summary>
  67. /// Return a clone of this object
  68. /// </summary>
  69. public object Clone()
  70. {
  71. return new OperatingSystem(itsPlatform, itsVersion);
  72. }
  73. /// <summary>
  74. /// Return true if obj equals this object
  75. /// </summary>
  76. public override bool Equals(object obj)
  77. {
  78. //Check for null and compare run-time types.
  79. if (obj == null || GetType() != obj.GetType()) return false;
  80. OperatingSystem os = (OperatingSystem)obj;
  81. return (itsPlatform == os.itsPlatform) &&
  82. (os.itsVersion.Equals(itsVersion));
  83. }
  84. /// <summary>
  85. /// Return hash code
  86. /// </summary>
  87. public override int GetHashCode()
  88. {
  89. return ((int)itsPlatform << 24) | itsVersion.GetHashCode() >> 8;
  90. }
  91. /// <summary>
  92. /// Return a string reprentation of this instance
  93. /// </summary>
  94. public override string ToString()
  95. {
  96. return itsPlatform.ToString() + ", " + itsVersion.ToString();
  97. }
  98. }
  99. }