Functions/New-MockObject.ps1
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 |
function New-MockObject { <# .SYNOPSIS This function instantiates a .NET object from a type. The assembly for the particular type must be loaded. .PARAMETER Type The .NET type to create an object from. .EXAMPLE PS> $obj = New-MockObject -Type 'System.Diagnostics.Process' PS> $obj.GetType().FullName System.Diagnostics.Process #> param ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [type]$Type ) [System.Runtime.Serialization.Formatterservices]::GetUninitializedObject($Type) } |