Skip to content

Instantly share code, notes, and snippets.

@dnasca
Created May 9, 2015 06:01
Show Gist options
  • Select an option

  • Save dnasca/f59c1acc09d96f99abfa to your computer and use it in GitHub Desktop.

Select an option

Save dnasca/f59c1acc09d96f99abfa to your computer and use it in GitHub Desktop.
using the PSClass CmdLet and implementing a basic class in Powershell 5
$ApplicationClass = new-psclass Application {
note -static objectCount 0
method -static displayObjectCount {
"$($this.ClassName) has $($this.ObjectCount) instances"
}
note -private Name
note -private Path
constructor {
para ($name, $path)
$private.Name = $name
$private.Path = $path
$ApplicationClass.ObjectCount +=1
}
property Name -get {
$private.Name
} -set {
param($newName)
write-host "Renaming $($this.Class.ClassName) '$($private.Name)' to '$($newName)'"
$private.Name = $newName
}
property Path -get {
$private.Path
}
method -override ToString {
"name: $($this.Class.ClassName) over-ride example: $($this.Name) path: $($this.Path)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment