Skip to content

Instantly share code, notes, and snippets.

@vors
Created March 11, 2015 16:40
Show Gist options
  • Save vors/ae0d58c3737bff092309 to your computer and use it in GitHub Desktop.
Save vors/ae0d58c3737bff092309 to your computer and use it in GitHub Desktop.
Workaround that can be used in WMF 5 February Preview to emulate const.
# don't use it, it's a workaround
class ClassWithConst
{
[ValidateSet(100)]
static [int] $CONST_FOO = 100
}
[ClassWithConst]::CONST_FOO
[ClassWithConst]::CONST_FOO = 10
# Output
100
Exception setting "CONST_FOO": "The argument "10" does not belong to the set "100" specified by the ValidateSet
attribute. Supply an argument that is in the set and then try the command again."
At line:8 char:1
+ [ClassWithConst]::CONST_FOO = 10
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment