Created
January 18, 2018 15:21
-
-
Save mkht/dfc7e7c5a41a6fb4fb55213ef6837f15 to your computer and use it in GitHub Desktop.
PowerShell class accessor
This file contains 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
# Original code | |
# https://stackoverflow.com/questions/39717230/powershell-class-implement-get-set-property | |
# This technique is so impressive! | |
class c { | |
hidden $_p = $($this | Add-Member ScriptProperty 'p' ` | |
{ | |
# get | |
"getter $($this._p)" | |
}` | |
{ | |
# set | |
param ( $arg ) | |
$this._p = "setter $arg" | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment