mscorlib(4.0.0.0) API with additions
OperatingSystem.cs
3 using System.Security;
4 
5 namespace System
6 {
9  [ComVisible(true)]
10  public sealed class OperatingSystem : ICloneable, ISerializable
11  {
12  private Version _version;
13 
14  private PlatformID _platform;
15 
16  private string _servicePack;
17 
18  private string _versionString;
19 
22  public PlatformID Platform => _platform;
23 
26  public string ServicePack
27  {
28  get
29  {
30  if (_servicePack == null)
31  {
32  return string.Empty;
33  }
34  return _servicePack;
35  }
36  }
37 
40  public Version Version => _version;
41 
44  public string VersionString
45  {
46  get
47  {
48  if (_versionString != null)
49  {
50  return _versionString;
51  }
52  string str;
53  switch (_platform)
54  {
55  case PlatformID.Win32NT:
56  str = "Microsoft Windows NT ";
57  break;
58  case PlatformID.Win32Windows:
59  str = ((_version.Major <= 4 && (_version.Major != 4 || _version.Minor <= 0)) ? "Microsoft Windows 95 " : "Microsoft Windows 98 ");
60  break;
61  case PlatformID.Win32S:
62  str = "Microsoft Win32S ";
63  break;
64  case PlatformID.WinCE:
65  str = "Microsoft Windows CE ";
66  break;
67  case PlatformID.MacOSX:
68  str = "Mac OS X ";
69  break;
70  default:
71  str = "<unknown> ";
72  break;
73  }
74  if (string.IsNullOrEmpty(_servicePack))
75  {
76  _versionString = str + _version.ToString();
77  }
78  else
79  {
80  _versionString = str + _version.ToString(3) + " " + _servicePack;
81  }
82  return _versionString;
83  }
84  }
85 
86  private OperatingSystem()
87  {
88  }
89 
97  public OperatingSystem(PlatformID platform, Version version)
98  : this(platform, version, null)
99  {
100  }
101 
102  internal OperatingSystem(PlatformID platform, Version version, string servicePack)
103  {
104  if (platform < PlatformID.Win32S || platform > PlatformID.MacOSX)
105  {
106  throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)platform), "platform");
107  }
108  if ((object)version == null)
109  {
110  throw new ArgumentNullException("version");
111  }
112  _platform = platform;
113  _version = (Version)version.Clone();
114  _servicePack = servicePack;
115  }
116 
117  private OperatingSystem(SerializationInfo info, StreamingContext context)
118  {
119  SerializationInfoEnumerator enumerator = info.GetEnumerator();
120  while (enumerator.MoveNext())
121  {
122  switch (enumerator.Name)
123  {
124  case "_version":
125  _version = (Version)info.GetValue("_version", typeof(Version));
126  break;
127  case "_platform":
128  _platform = (PlatformID)info.GetValue("_platform", typeof(PlatformID));
129  break;
130  case "_servicePack":
131  _servicePack = info.GetString("_servicePack");
132  break;
133  }
134  }
135  if (_version == null)
136  {
137  throw new SerializationException(Environment.GetResourceString("Serialization_MissField", "_version"));
138  }
139  }
140 
146  [SecurityCritical]
148  {
149  if (info == null)
150  {
151  throw new ArgumentNullException("info");
152  }
153  info.AddValue("_version", _version);
154  info.AddValue("_platform", _platform);
155  info.AddValue("_servicePack", _servicePack);
156  }
157 
160  public object Clone()
161  {
162  return new OperatingSystem(_platform, _version, _servicePack);
163  }
164 
167  public override string ToString()
168  {
169  return VersionString;
170  }
171  }
172 }
PlatformID
Identifies the operating system, or platform, supported by an assembly.
Definition: PlatformID.cs:8
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override string ToString()
Converts the value of this T:System.OperatingSystem object to its equivalent string representation.
Definition: __Canon.cs:3
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Version Version
Gets a T:System.Version object that identifies the operating system.
PlatformID Platform
Gets a T:System.PlatformID enumeration value that identifies the operating system platform.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
string? VersionString
Gets the concatenated string representation of the platform identifier, version, and service pack tha...
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo object with the data necessary to deseri...
OperatingSystem(PlatformID platform, Version version)
Initializes a new instance of the T:System.OperatingSystem class, using the specified platform identi...
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Definition: ICloneable.cs:7
object Clone()
Creates an T:System.OperatingSystem object that is identical to this instance.
Represents the version number of an assembly, operating system, or the common language runtime....
Definition: Version.cs:11
The exception thrown when an error occurs during serialization or deserialization.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Represents information about an operating system, such as the version and platform identifier....
The exception that is thrown when one of the arguments provided to a method is not valid.
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
Specifies that the class can be serialized.
string Name
Gets the name for the item currently being examined.
string ServicePack
Gets the service pack version represented by this T:System.OperatingSystem object.
object Clone()
Returns a new T:System.Version object whose value is the same as the current T:System....
Definition: Version.cs:277
Provides a formatter-friendly mechanism for parsing the data in T:System.Runtime.Serialization....
bool MoveNext()
Updates the enumerator to the next item.