2002-01-14 Miguel de Icaza <miguel@ximian.com>
[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 using System.Globalization;\r
14 \r
15 namespace System\r
16 {\r
17         /// <summary>\r
18         /// Class representing a specific operating system version for a specific platform\r
19         /// </summary>\r
20         public sealed class OperatingSystem : ICloneable\r
21         {\r
22                 private System.PlatformID itsPlatform;\r
23                 private Version itsVersion;\r
24 \r
25                 public OperatingSystem(PlatformID platform, Version version)\r
26                 {\r
27                         if(version == null)\r
28                         {\r
29                                 throw new ArgumentNullException();\r
30                         }\r
31                         \r
32                         itsPlatform = platform;\r
33                         itsVersion = version;\r
34                 }\r
35 \r
36                 /// <summary>\r
37                 /// Get the PlatformID\r
38                 /// </summary>\r
39                 public PlatformID Platform\r
40                 {\r
41                         get\r
42                         {\r
43                                 return itsPlatform;\r
44                         }\r
45                 }\r
46 \r
47                 /// <summary>\r
48                 /// Gets the version object\r
49                 /// </summary>\r
50                 public Version Version\r
51                 {\r
52                         get\r
53                         {\r
54                                 return itsVersion;\r
55                         }\r
56                 }\r
57 \r
58                 /// <summary>\r
59                 /// Return a clone of this object\r
60                 /// </summary>\r
61                 public object Clone()\r
62                 {\r
63                         return new OperatingSystem(itsPlatform, itsVersion);\r
64                 }\r
65 \r
66                 /// <summary>\r
67                 /// Return true if obj equals this object\r
68                 /// </summary>\r
69                 public override bool Equals(object obj)\r
70                 {\r
71                         //Check for null and compare run-time types.\r
72                         if (obj == null || GetType() != obj.GetType()) return false;\r
73                         OperatingSystem os = (OperatingSystem)obj;\r
74                         return (itsPlatform == os.itsPlatform) && \r
75                                 (os.itsVersion.Equals(itsVersion));\r
76                 }\r
77 \r
78                 /// <summary>\r
79                 /// Return hash code\r
80                 /// </summary>\r
81                 public override int GetHashCode()\r
82                 {       // this leave us enuf for 256 unique platforms which should suffice for a good while\r
83                         return ((int)itsPlatform << 24) | itsVersion.GetHashCode() >> 8;\r
84                 }\r
85 \r
86                 /// <summary>\r
87                 /// Return a string reprentation of this instance\r
88                 /// </summary>\r
89                 public override string ToString()\r
90                 {\r
91                         string str;\r
92                         \r
93                         switch(itsPlatform)\r
94                         {\r
95                         case System.PlatformID.Win32NT: str = "Microsoft Windows NT"; break;\r
96                         case System.PlatformID.Win32S: str = "Microsoft Win32S";  break;\r
97                         case System.PlatformID.Win32Windows: str = "Microsoft Windows 98"; break;\r
98                         case System.PlatformID.Unix: str = "Unix"; break;\r
99                         default: str = Locale.GetText ("<unknown>"); break;\r
100                         }\r
101 \r
102                         return str + " " + itsVersion.ToString();\r
103                 }\r
104         }\r
105 }\r