OperatingSystem.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //------------------------------------------------------------------------------
  2. //
  3. // System.OperatingSystem.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 System
  13. {
  14. /// <summary>
  15. /// Class representing a specific operating system version for a specific platform
  16. /// </summary>
  17. public sealed class OperatingSystem : ICloneable
  18. {
  19. private PlatformID itsPlatform;
  20. private Version itsVersion;
  21. public OperatingSystem(PlatformID platform, Version version)
  22. {
  23. if(version == null)
  24. {
  25. throw new ArgumentNullException();
  26. }
  27. // the doc doesn't say this, but I would
  28. //if(platform < minPlatform || platform >= maxPlatform)
  29. //{
  30. // throw new ArgumentOutOfRangeException();
  31. // TODO: find out if C# has assertion mechanism
  32. // isn't learning new languages fun? :)
  33. //}
  34. itsPlatform = platform;
  35. itsVersion = version;
  36. }
  37. /// <summary>
  38. /// Get the PlatformID
  39. /// </summary>
  40. public PlatformID Platform
  41. {
  42. get
  43. {
  44. return itsPlatform;
  45. }
  46. }
  47. /// <summary>
  48. /// Gets the version object
  49. /// </summary>
  50. public Version Version
  51. {
  52. get
  53. {
  54. return itsVersion;
  55. }
  56. }
  57. /// <summary>
  58. /// Return a clone of this object
  59. /// </summary>
  60. public object Clone()
  61. {
  62. return new OperatingSystem(itsPlatform, itsVersion);
  63. }
  64. /// <summary>
  65. /// Return true if obj equals this object
  66. /// </summary>
  67. public override bool Equals(object obj)
  68. {
  69. //Check for null and compare run-time types.
  70. if (obj == null || GetType() != obj.GetType()) return false;
  71. OperatingSystem os = (OperatingSystem)obj;
  72. return (itsPlatform == os.itsPlatform) &&
  73. (os.itsVersion.Equals(itsVersion));
  74. }
  75. /// <summary>
  76. /// Return hash code
  77. /// </summary>
  78. public override int GetHashCode()
  79. {
  80. return ((int)itsPlatform << 24) | itsVersion.GetHashCode() >> 8;
  81. }
  82. /// <summary>
  83. /// Return a string reprentation of this instance
  84. /// </summary>
  85. public override string ToString()
  86. {
  87. return itsPlatform.ToString() + ", " + itsVersion.ToString();
  88. }
  89. }
  90. }