Skip to content

Instantly share code, notes, and snippets.

@mkht
Created January 18, 2018 15:21
Show Gist options
  • Save mkht/dfc7e7c5a41a6fb4fb55213ef6837f15 to your computer and use it in GitHub Desktop.
Save mkht/dfc7e7c5a41a6fb4fb55213ef6837f15 to your computer and use it in GitHub Desktop.
PowerShell class accessor
# 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