-
-
Save dlwyatt/aa1a76ab8829b84b1460 to your computer and use it in GitHub Desktop.
Playing with the new Class definition syntax in PowerShell 5.0 preview
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
enum MyTestEnum | |
{ | |
FirstValue = 1 | |
SecondValue = 2 | |
ThirdValue = 4 | |
AllValues = 7 | |
} | |
class MyTestClass | |
{ | |
[int] $MyIntProperty = 1 | |
# Even though I can assign [MyTestEnum]::FirstValue to a varible here, for some reason a type | |
# constraint attribute can't find the [MyTestEnum] type. Presumably this will be working before | |
# release | |
#[MyTestEnum] $MyEnum = [MyTestEnum]::FirstValue | |
[bool] def MyMethod | |
{ | |
return $true | |
} | |
static [int] $MyStaticIntProperty = 5 | |
static [int] def MyStaticMethod | |
{ | |
return 20 | |
} | |
} | |
$object = New-Object MyTestClass | |
$object.MyIntProperty = 5 | |
$object.MyMethod() | |
$object.GetType() | |
[MyTestClass]::MyStaticIntProperty = 10 | |
[MyTestClass]::MyStaticIntProperty | |
[MyTestClass]::MyStaticMethod() | |
[MyTestEnum]::AllValues |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment