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
26
27
28
29
function New-MockObject {
<#
.SYNOPSIS
This function instantiates a .NET object from a type.
 
.DESCRIPTION
Using the New-MockObject you can mock an object based on .NET type.
 
An .NET assembly for the particular type must be available in the system and loaded.
 
.PARAMETER Type
The .NET type to create an object based on.
 
.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)

}