// Copy, clone, and duplicate an OperatingSystem object. static void CopyOperatingSystemObjects( ) { // The Version object does not need to correspond to an // actual OS version. Version verMMBVer = new Version(5, 6, 7, 8); OperatingSystem opCreate1 = new OperatingSystem(PlatformID.Win32NT, verMMBVer); // Create another OperatingSystem object with the same // parameters as opCreate1. OperatingSystem opCreate2 = new OperatingSystem(PlatformID.Win32NT, verMMBVer); // Clone opCreate1 and copy the opCreate1 reference. OperatingSystem opClone = (OperatingSystem)opCreate1.Clone( ); OperatingSystem opCopy = opCreate1; // Compare the various objects for equality. Console.WriteLine("{0,-50}{1}", "Is the second object the same as the original?", opCreate1.Equals(opCreate2)); Console.WriteLine("{0,-50}{1}", "Is the object clone the same as the original?", opCreate1.Equals(opClone)); Console.WriteLine("{0,-50}{1}", "Is the copied object the same as the original?", opCreate1.Equals(opCopy)); }
/// <summary> /// Create a deep clone of the platform data object. /// </summary> public object Clone() { return(new PlatformData() { Dotnet = (DotnetData)Dotnet.Clone(), OperatingSystem = (OperatingSystemData)OperatingSystem.Clone(), PowerShell = (PowerShellData)PowerShell.Clone() }); }
public static void Clone() { var os = new OperatingSystem(PlatformID.Xbox, new Version(1, 2, 3, 4)); var os2 = (OperatingSystem)os.Clone(); Assert.Equal(os.Platform, os2.Platform); Assert.Equal(os.ServicePack, os2.ServicePack); Assert.Equal(os.Version, os2.Version); Assert.Equal(os.VersionString, os2.VersionString); }
public void Clone_CopyValues() { var sut = new OperatingSystem { Name = "name", KernelVersion = "KernelVersion", RawDescription = "RawDescription", Rooted = true, Build = "build", Version = "version" }; var clone = sut.Clone(); Assert.Equal(sut.Name, clone.Name); Assert.Equal(sut.KernelVersion, clone.KernelVersion); Assert.Equal(sut.RawDescription, clone.RawDescription); Assert.Equal(sut.Rooted, clone.Rooted); Assert.Equal(sut.Build, clone.Build); Assert.Equal(sut.Version, clone.Version); }
/// <summary> /// Creates an <see cref="OperatingSystemInfo"/> object that is identical to this instance. /// </summary> /// <returns></returns> public object Clone() { return(_operatingSystem.Clone()); }