Welcome to mirror list, hosted at ThFree Co, Russian Federation.

OperatingSystem.cs « System « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 93729bb4a4515c4c1f9d1e0ca5ba1732c1882207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//------------------------------------------------------------------------------
// 
// System.OperatingSystem.cs 
//
// Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
// 
// Author:         Jim Richardson, develop@wtfo-guru.com
// Created:        Saturday, August 11, 2001 
//
//------------------------------------------------------------------------------

using System;
using System.Globalization;

namespace System
{
	/// <summary>
	/// Class representing a specific operating system version for a specific platform
	/// </summary>
	[Serializable]
	public sealed class OperatingSystem : ICloneable
	{
		private System.PlatformID itsPlatform;
		private Version itsVersion;

		public OperatingSystem(PlatformID platform, Version version)
		{
			if(version == null)
			{
				throw new ArgumentNullException();
			}
			
			itsPlatform = platform;
			itsVersion = version;
		}

		/// <summary>
		/// Get the PlatformID
		/// </summary>
		public PlatformID Platform
		{
			get
			{
				return itsPlatform;
			}
		}

		/// <summary>
		/// Gets the version object
		/// </summary>
		public Version Version
		{
			get
			{
				return itsVersion;
			}
		}

		/// <summary>
		/// Return a clone of this object
		/// </summary>
		public object Clone()
		{
			return new OperatingSystem(itsPlatform, itsVersion);
		}

		/// <summary>
		/// Return true if obj equals this object
		/// </summary>
		public override bool Equals(object obj)
		{
			//Check for null and compare run-time types.
			if (obj == null || GetType() != obj.GetType()) return false;
			OperatingSystem os = (OperatingSystem)obj;
			return (itsPlatform == os.itsPlatform) && 
				(os.itsVersion.Equals(itsVersion));
		}

		/// <summary>
		/// Return hash code
		/// </summary>
		public override int GetHashCode()
		{	// this leave us enuf for 256 unique platforms which should suffice for a good while
			return ((int)itsPlatform << 24) | itsVersion.GetHashCode() >> 8;
		}

		/// <summary>
		/// Return a string reprentation of this instance
		/// </summary>
		public override string ToString()
		{
			string str;
			
			switch(itsPlatform)
			{
			case System.PlatformID.Win32NT: str = "Microsoft Windows NT"; break;
			case System.PlatformID.Win32S: str = "Microsoft Win32S";  break;
			case System.PlatformID.Win32Windows: str = "Microsoft Windows 98"; break;
			case System.PlatformID.Unix: str = "Unix"; break;
			default: str = Locale.GetText ("<unknown>"); break;
			}

			return str + " " + itsVersion.ToString();
		}
	}
}