Skip to content

Instantly share code, notes, and snippets.

@Stephanevg
Last active April 20, 2017 13:18
Show Gist options
  • Save Stephanevg/f4f502cfdf184d125c13240fc9d2e004 to your computer and use it in GitHub Desktop.
Save Stephanevg/f4f502cfdf184d125c13240fc9d2e004 to your computer and use it in GitHub Desktop.
Make clone an existing PowerShell class using IClonable Interface
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