2010-03-22 28 views
7

我想在PowerShell中使用Enumerable.ToList()。显然,要做到这一点,我必须明确地将对象转换为IEnumerable<CustomType>,但我无法做到这一点。看来我无法在PowerShell中正确编写IEnumerable<CustomType>IEnumerable<string>CustomType本身都能正常工作(我试图使用的自定义类型叫做WpApiLib.Page),所以我不知道我能做什么错。IEnumerable <CustomType> in PowerShell

PS C:\Users\Svick> [Collections.Generic.IEnumerable``1[System.String]] 

IsPublic IsSerial Name          BaseType 
-------- -------- ----          -------- 
True  False IEnumerable`1 


PS C:\Users\Svick> [WpApiLib.Page] 

IsPublic IsSerial Name          BaseType 
-------- -------- ----          -------- 
True  True  Page          System.Object 


PS C:\Users\Svick> [Collections.Generic.IEnumerable``1[WpApiLib.Page]] 
Unable to find type [Collections.Generic.IEnumerable`1[WpApiLib.Page]]: make su 
re that the assembly containing this type is loaded. 
At line:1 char:51 
+ [Collections.Generic.IEnumerable``1[WpApiLib.Page]] <<<< 

回答

3

请在这里看到答案:Powershell Generic Collections。看起来这是PowerShell如何解释泛型的一个不幸后果,并且您需要完全限定WpApiLib.Page类型。

+0

哎哟,真的很丑,谢谢 – svick 2010-03-22 21:18:24

6

在PowerShell中2版,您可以使用

Collections.Generic.IEnumerable[string] 

IEnumberable<string>。该语法适用于New-Object(尽管不是用于接口),它似乎也适用于演员表。

相关问题