Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 接收作业未使我的对象保持有序_Powershell_Powershell 3.0_Powershell 4.0 - Fatal编程技术网

Powershell 接收作业未使我的对象保持有序

Powershell 接收作业未使我的对象保持有序,powershell,powershell-3.0,powershell-4.0,Powershell,Powershell 3.0,Powershell 4.0,我正在尝试为从另一个脚本开始的启动作业中运行的powershell脚本返回一个有序的措辞 被调用的脚本返回一个变量$readahead,其类型如下: [DBG]: [Job23]: PS C:\Users\litroma\Documents>> $readahead.GetType() IsPublic IsSerial Name BaseType -------- -------- ----

我正在尝试为从另一个脚本开始的启动作业中运行的powershell脚本返回一个有序的措辞

被调用的脚本返回一个变量$readahead,其类型如下:

[DBG]: [Job23]: PS C:\Users\litroma\Documents>> $readahead.GetType()
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     OrderedDictionary                        System.Object
[DBG]: PS C:\Users\litroma\Documents>> $ret.GetType()
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     -------- 
True     True     Hashtable                                System.Object
但是,一旦从调用方脚本中检索到此变量,则:

$ret=receive-job -Job $job
$ret变量就是这种类型:

[DBG]: [Job23]: PS C:\Users\litroma\Documents>> $readahead.GetType()
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     OrderedDictionary                        System.Object
[DBG]: PS C:\Users\litroma\Documents>> $ret.GetType()
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     -------- 
True     True     Hashtable                                System.Object
你知道如何通过接收作业保持我的[ordered]类型吗

短暂性脑缺血发作


关于

这里的问题是,为了从执行作业的外部进程获取结果,它需要序列化运行时对象

不幸的是,序列化过程似乎将任何
字典
类型转换为
哈希表

您可以通过导出和重新导入已排序的字典对象来查看此效果:

PS C:\> [ordered]@{1=1;2=2;3=3} |Export-Clixml ($tmpFile = [System.IO.Path]::GetTempFileName())
PS C:\> (Import-Clixml $tmpFile).GetType().FullName
System.Collections.Hashtable
如果不对
OrderedDictionary
类进行一些认真的扩展,使代码的可重用性降低,我认为这是无法克服的


另一种方法是返回一个对象数组(数组是有序的),然后在收到作业后重新创建
OrderedDictionary
这里的问题是,为了从执行作业的外部进程获取结果,它需要序列化运行时对象

不幸的是,序列化过程似乎将任何
字典
类型转换为
哈希表

您可以通过导出和重新导入已排序的字典对象来查看此效果:

PS C:\> [ordered]@{1=1;2=2;3=3} |Export-Clixml ($tmpFile = [System.IO.Path]::GetTempFileName())
PS C:\> (Import-Clixml $tmpFile).GetType().FullName
System.Collections.Hashtable
如果不对
OrderedDictionary
类进行一些认真的扩展,使代码的可重用性降低,我认为这是无法克服的


另一种方法是返回一个对象数组(数组是有序的),然后在收到作业后重新创建
OrderedDictionary
,在这里泛型不是一个好词,因为
Hashtable
在.NET术语中不是泛型类。@PetSerAl true,删除它以避免混淆感谢Mathias的提示。IMHO,泛型在这里不是一个好术语,因为在.NET术语中,
Hashtable
不是泛型类。@PetSerAl true,删除它以避免混淆感谢Mathias提供的提示。