title: Use custom PowerShell defined type for parameter type specification
body: <p>I define a custom PowerShell type with New-Object. I would like a parameter to be of my defined type, is it possible to specify this type in a declarative way? The following code gives me the error: "Unable to find type [BuildActionContext]: make sure that the assembly containing this type is loaded."</p>
  
  <p>Can we specify the type declarative, or should I just test the type of the specified object?</p>
  
  <p>Not working code:</p>
  
  <pre><code>$buildActionContext = New-Object -TypeName PSObject -Property @{
  # Given properties
  BuildAction = "Build"; 
  }
  $buildActionContext.PSObject.TypeNames.Insert(0, 'BuildActionContext')
  
  function DoSomethingWithBuildActionContext
  {
  [CmdletBinding()]
  param
  (
      [Parameter(Mandatory=$true)][BuildActionContext]$Context
  )
  
  Write-Host "Build action: $($Context.BuildAction)"
  }
  
  DoSomethingWithBuildActionContext -Context $buildActionContext
  </code></pre>
  
  <p>Working code, but can it be done differently:</p>
  
  <pre><code>$buildActionContext = New-Object -TypeName PSObject -Property @{
          # Given properties
          BuildAction = "Build"; 
      }
      $buildActionContext.PSObject.TypeNames.Insert(0, 'BuildActionContext')
  
  function DoSomethingWithBuildActionContext
  {
      [CmdletBinding()]
      param
      (
          [Parameter(Mandatory=$true)]$Context
      )
  
      if ($Context.PSObject.TypeNames[0] -ne 'BuildActionContext')
      {
          throw "Context parameter not of type 'BuildActionContext'"
      }
  
      Write-Host "Build action: $($Context.BuildAction)"
  }
  
  DoSomethingWithBuildActionContext -Context $buildActionContext
  DoSomethingWithBuildActionContext -Context "Hello world"
  </code></pre>
  
  <p>Note: Second call gives the exception message.</p>