mardi 15 mars 2016

Pass interface type to c# in Powershell script?

I have a C# library that I'm trying to script against where one of the most important calls has the following method signature:

DoThing(IDictionary<int, IList<int>> dict)

I need to write a powershell script that constructs an object to be passed in. I have written powershell to construct the same thing, but with concrete classes:

$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)

However, this is effectively creating a Dictionary<int, List<int>> object, which is (for some reason; I don't know why) incompatible with IDictionary<int, IList<int>>.

How can I create a compatible type in powershell?





Aucun commentaire:

Enregistrer un commentaire