2010-03-22 39 views
7

Sto cercando di utilizzare Enumerable.ToList() in PowerShell. Apparentemente, per farlo, devo convertire esplicitamente l'oggetto in IEnumerable<CustomType>, ma non riesco a farlo. Sembra che non riesca a scrivere correttamente IEnumerable<CustomType> in PowerShell. Entrambi IEnumerable<string> e CustomType funzionano correttamente (il tipo personalizzato che sto tentando di utilizzare si chiama WpApiLib.Page), quindi non so cosa posso fare.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]] <<<< 

risposta

3

Vedere la risposta qui: Powershell Generic Collections. Sembra che questa sia una sfortunata conseguenza di come PowerShell interpreta i generici e sarà necessario qualificare in modo completo il tipo WpApiLib.Page.

+0

ahi, è davvero brutto, grazie – svick

6

In PowerShell v2 è possibile utilizzare

Collections.Generic.IEnumerable[string] 

per riferirsi a IEnumberable<string>. La sintassi funziona per New-Object (sebbene non con un'interfaccia) e sembra essere valida anche per i cast.

Problemi correlati