Additional implementation
[mono.git] / mcs / class / corlib / System / OperatingSystem.cs
1 //------------------------------------------------------------------------------\r
2 // \r
3 // System.OperatingSystem.cs \r
4 //\r
5 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved\r
6 // \r
7 // Author:         Jim Richardson, develop@wtfo-guru.com\r
8 // Created:        Saturday, August 11, 2001 \r
9 //\r
10 //------------------------------------------------------------------------------\r
11 \r
12 using System;\r
13 \r
14 namespace System\r
15 {\r
16         /// <summary>\r
17         /// Class representing a specific operating system version for a specific platform\r
18         /// </summary>\r
19         public sealed class OperatingSystem : ICloneable\r
20         {\r
21                 private System.PlatformID itsPlatform;\r
22                 private Version itsVersion;\r
23 \r
24                 public OperatingSystem(PlatformID platform, Version version)\r
25                 {\r
26                         if(version == null)\r
27                         {\r
28                                 throw new ArgumentNullException();\r
29                         }\r
30                         \r
31                         itsPlatform = platform;\r
32                         itsVersion = version;\r
33                 }\r
34 \r
35                 /// <summary>\r
36                 /// Get the PlatformID\r
37                 /// </summary>\r
38                 public PlatformID Platform\r
39                 {\r
40                         get\r
41                         {\r
42                                 return itsPlatform;\r
43                         }\r
44                 }\r
45 \r
46                 /// <summary>\r
47                 /// Gets the version object\r
48                 /// </summary>\r
49                 public Version Version\r
50                 {\r
51                         get\r
52                         {\r
53                                 return itsVersion;\r
54                         }\r
55                 }\r
56 \r
57                 /// <summary>\r
58                 /// Return a clone of this object\r
59                 /// </summary>\r
60                 public object Clone()\r
61                 {\r
62                         return new OperatingSystem(itsPlatform, itsVersion);\r
63                 }\r
64 \r
65                 /// <summary>\r
66                 /// Return true if obj equals this object\r
67                 /// </summary>\r
68                 public override bool Equals(object obj)\r
69                 {\r
70                         //Check for null and compare run-time types.\r
71                         if (obj == null || GetType() != obj.GetType()) return false;\r
72                         OperatingSystem os = (OperatingSystem)obj;\r
73                         return (itsPlatform == os.itsPlatform) && \r
74                                 (os.itsVersion.Equals(itsVersion));\r
75                 }\r
76 \r
77                 /// <summary>\r
78                 /// Return hash code\r
79                 /// </summary>\r
80                 public override int GetHashCode()\r
81                 {       // this leave us enuf for 256 unique platforms which should suffice for a good while\r
82                         return ((int)itsPlatform << 24) | itsVersion.GetHashCode() >> 8;\r
83                 }\r
84 \r
85                 /// <summary>\r
86                 /// Return a string reprentation of this instance\r
87                 /// </summary>\r
88                 public override string ToString()\r
89                 {\r
90                         string str;\r
91                         \r
92                         switch(itsPlatform)\r
93                         {\r
94                         case System.PlatformID.Win32NT: str = "Microsoft Windows NT"; break;\r
95                         case System.PlatformID.Win32S: str = "Microsoft Win32S";  break;\r
96                         case System.PlatformID.Win32Windows: str = "Microsoft Windows 98"; break;\r
97                         case System.PlatformID.Linux: str = "Linux"; break;\r
98                         default: str = "<unknown>";      break;\r
99                         }\r
100 \r
101                         return str + " " + itsVersion.ToString();\r
102                 }\r
103         }\r
104 }\r