OperatingSystem.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 System.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. itsPlatform = platform;
  28. itsVersion = version;
  29. }
  30. /// <summary>
  31. /// Get the PlatformID
  32. /// </summary>
  33. public PlatformID Platform
  34. {
  35. get
  36. {
  37. return itsPlatform;
  38. }
  39. }
  40. /// <summary>
  41. /// Gets the version object
  42. /// </summary>
  43. public Version Version
  44. {
  45. get
  46. {
  47. return itsVersion;
  48. }
  49. }
  50. /// <summary>
  51. /// Return a clone of this object
  52. /// </summary>
  53. public object Clone()
  54. {
  55. return new OperatingSystem(itsPlatform, itsVersion);
  56. }
  57. /// <summary>
  58. /// Return true if obj equals this object
  59. /// </summary>
  60. public override bool Equals(object obj)
  61. {
  62. //Check for null and compare run-time types.
  63. if (obj == null || GetType() != obj.GetType()) return false;
  64. OperatingSystem os = (OperatingSystem)obj;
  65. return (itsPlatform == os.itsPlatform) &&
  66. (os.itsVersion.Equals(itsVersion));
  67. }
  68. /// <summary>
  69. /// Return hash code
  70. /// </summary>
  71. public override int GetHashCode()
  72. { // this leave us enuf for 256 unique platforms which should suffice for a good while
  73. return ((int)itsPlatform << 24) | itsVersion.GetHashCode() >> 8;
  74. }
  75. /// <summary>
  76. /// Return a string reprentation of this instance
  77. /// </summary>
  78. public override string ToString()
  79. {
  80. string str;
  81. switch(itsPlatform)
  82. {
  83. case System.PlatformID.Win32NT: str = "Microsoft Windows NT"; break;
  84. case System.PlatformID.Win32S: str = "Microsoft Win32S"; break;
  85. case System.PlatformID.Win32Windows: str = "Microsoft Windows 98"; break;
  86. case System.PlatformID.Unix: str = "Unix"; break;
  87. default: str = "<unknown>"; break;
  88. }
  89. return str + " " + itsVersion.ToString();
  90. }
  91. }
  92. }