2010-03-22 9 views
7

Estoy tratando de usar Enumerable.ToList() en PowerShell. Aparentemente, para hacer eso, tengo que convertir explícitamente el objeto a IEnumerable<CustomType>, pero no puedo hacer eso. Parece que no puedo escribir correctamente IEnumerable<CustomType> en PowerShell. Tanto IEnumerable<string> como CustomType funcionan correctamente (el tipo personalizado que intento usar se llama WpApiLib.Page), así que no sé qué puedo estar haciendo mal.IEnumerable <CustomType> en 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]] <<<< 

Respuesta

3

Ver la respuesta aquí: Powershell Generic Collections. Parece que esto es una desafortunada consecuencia de cómo PowerShell interpreta los genéricos, y necesitará calificar completamente el tipo WpApiLib.Page.

+0

ouch, eso es realmente feo, gracias – svick

6

En PowerShell V2 puede utilizar

Collections.Generic.IEnumerable[string] 

para referirse a IEnumberable<string>. La sintaxis funciona para New-Object (aunque no con una interfaz) y parece ser válida también para moldes.

Cuestiones relacionadas