Dependencies/Axiom/Verify-Type.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function Verify-Type {
    param (
        [Parameter(ValueFromPipeline=$true)]
        $Actual,
        [Parameter(Mandatory=$true,Position=0)]
        [Type]$Expected
    )

    if ($Actual -isnot $Expected) {
        $message = "Expected value to be of type $($Expected.FullName)"
        $Actual = "but got " + $(if ($null -eq $Actual) { "'<null>'" }
                    else { "'$($Actual.GetType().FullName)'" })
        throw [Exception]"$message, $Actual"
    }

    $Actual
}