Skip to content

Instantly share code, notes, and snippets.

@dlwyatt
Created July 21, 2014 01:05
Show Gist options
  • Save dlwyatt/aa1a76ab8829b84b1460 to your computer and use it in GitHub Desktop.
Save dlwyatt/aa1a76ab8829b84b1460 to your computer and use it in GitHub Desktop.
Playing with the new Class definition syntax in PowerShell 5.0 preview
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