svi*_*ick 7 .net generics powershell ienumerable
我正在尝试Enumerable.ToList()在PowerShell中使用.显然,要做到这一点,我必须明确地将对象转换为IEnumerable<CustomType>,但我无法做到这一点.好像我无法IEnumerable<CustomType>在PowerShell中正确编写.无论IEnumerable<string>和CustomType自身正确的(我想使用自定义类型被称为工作WpApiLib.Page),所以我不知道我该怎么做是错误的.
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]] <<<<
Run Code Online (Sandbox Code Playgroud)
在PowerShell v2中,您可以使用
Collections.Generic.IEnumerable[string]
Run Code Online (Sandbox Code Playgroud)
参考IEnumberable<string>.语法适用于New-Object(虽然没有使用接口),它似乎也适用于强制转换.