【发布时间】:2016-07-01 08:53:25
【问题描述】:
我有一个 C# 库,我正在尝试编写脚本,其中最重要的调用之一具有以下方法签名:
DoThing(IDictionary<int, IList<int>> dict)
我需要编写一个构造要传入的对象的 powershell 脚本。我已经编写了 powershell 来构造相同的东西,但是使用了具体的类:
$myArg= New-Object 'Collections.Generic.Dictionary[int, Collections.Generic.List[int]]'
$list = New-Object 'Collections.Generic.List[int]'
$myArg.Add(7, $list)
[PowershellReflectionTest.ReflectionTester]::DoThing($myArg)
然而,这实际上是在创建一个Dictionary<int, List<int>> 对象,它(出于某种原因;我不知道为什么)与IDictionary<int, IList<int>> 不兼容。
如何在 powershell 中创建兼容类型?
【问题讨论】:
标签: c# .net powershell reflection scripting