Created
May 9, 2015 06:01
-
-
Save dnasca/f59c1acc09d96f99abfa to your computer and use it in GitHub Desktop.
using the PSClass CmdLet and implementing a basic class in Powershell 5
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
| $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