Last active
April 20, 2017 13:18
-
-
Save Stephanevg/f4f502cfdf184d125c13240fc9d2e004 to your computer and use it in GitHub Desktop.
Make clone an existing PowerShell class using IClonable Interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car { | |
[String] $Make | |
[String] $Model | |
[Object]Clone(){ | |
return $this.MemberwiseClone() | |
} | |
[void]Display(){ | |
Write-host "The car model is: $($this.Model) and make: $($this.Make)" | |
} | |
} | |
$Citroen = $null | |
$Citroen = [Car]::New() | |
$Citroen.make = "Citroen" | |
$Citroen.Model = "DS3" | |
$Citroen | |
$Citroen.Display() | |
$SecondCar = $null | |
$SecondCar = $Citroen.Clone() | |
$SecondCar | |
$SecondCar.Display() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment