Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
如何将代码中的C#字典转换为Powershell对象?_C#_Powershell_Powershell 2.0 - Fatal编程技术网

如何将代码中的C#字典转换为Powershell对象?

如何将代码中的C#字典转换为Powershell对象?,c#,powershell,powershell-2.0,C#,Powershell,Powershell 2.0,有人能帮我吗?我有构建字典的C#代码,需要将字典转换为PowerShell对象。然后将对象传递给PowerShell脚本 我的字典 Dictionary<string, Dictionary<string, string>> 字典 当前版本(v3/v4)应该能够直接使用字典,但我不记得v2如何处理泛型。无论如何,这里有一些伪代码(不保证编译)可以转换为哈希表的哈希表: var hashtable = new Hashtable(); foreach (var kvPa

有人能帮我吗?我有构建字典的C#代码,需要将字典转换为PowerShell对象。然后将对象传递给PowerShell脚本

我的字典

Dictionary<string, Dictionary<string, string>>
字典
当前版本(v3/v4)应该能够直接使用字典,但我不记得v2如何处理泛型。无论如何,这里有一些伪代码(不保证编译)可以转换为哈希表的哈希表:

var hashtable = new Hashtable();
foreach (var kvPair in dict) {
    var hashtableInner = new Hashtable();
    foreach (var kvPairInner in kvPair.Value) {
        hashtableInner.Add(kvPairInner.Key, kvPairInner.Value);
    }

    hashtable.Add(kvPair.Key, hashtableInner);
}

# Pass hashtable to PowerShell as even v2 understands .NET hashtables

你为什么需要转换?PowerShell可以使用字典。