CliXml序列化/反序列化丢失类型

时间:2015-03-23 13:31:48

标签: powershell serialization powershell-v4.0

此处的小函数显示在序列化/反序列化操作期间,我丢失了我的一个参数的Scriptblock类型。

Function CliXMLPOC ([String]$p1, [scriptblock]$p2)
{
  # $PSBoundParameters is an automatic var containing bound parameters
  Write-Host "BEFORE Members are : $($PSBoundParameters["p1"].GetType()), $($PSBoundParameters["p2"].GetType())"
  $serialized = [System.Management.Automation.PSSerializer]::Serialize($PSBoundParameters)
  $deserialized = [System.Management.Automation.PSSerializer]::Deserialize($serialized)
  Write-Host "AFTER Members are : $($deserialized["p1"].GetType()), $($deserialized["p2"].GetType())"
}

CliXMLPOC "Toto" {write-host "coucou"}

结果给出:

BEFORE Members are : string, scriptblock
AFTER Members are : string, string

任何人都可以解释这一点并帮助我检索预期的结果吗?

BEFORE Members are : string, scriptblock
AFTER Members are : string, scriptblock

0 个答案:

没有答案