此处的小函数显示在序列化/反序列化操作期间,我丢失了我的一个参数的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