forked from nightroman/PowerShellTraps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-1.ps1
More file actions
30 lines (19 loc) · 716 Bytes
/
Test-1.ps1
File metadata and controls
30 lines (19 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#requires -version 5
# Compile the attribute and two C# test classes
Add-Type -TypeDefinition ([IO.File]::ReadAllText("$PSScriptRoot\Lib.cs"))
# Import two PowerShell test classes
. $PSScriptRoot\Lib.ps1
### Test PowerShell classes
# get KnownTypeAttribute of T1
$r = [Attribute]::GetCustomAttribute([T1], [KnownTypeAttribute])
# KnownTypeAttribute, expected
$r.GetType().Name
# KnownType is null, unexpected -- THIS IS AN ISSUE
$r.KnownType -eq $null
### Test C# classes
# get KnownTypeAttribute of MyT1
$r = [Attribute]::GetCustomAttribute([MyT1], [KnownTypeAttribute])
# KnownTypeAttribute, expected
$r.GetType().Name
# KnownType is MyT2, expected (not null like in PowerShell)
$r.KnownType -eq [MyT2]