Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 在运行时按名称获取泛型类型_Powershell - Fatal编程技术网

Powershell 在运行时按名称获取泛型类型

Powershell 在运行时按名称获取泛型类型,powershell,Powershell,我想知道为什么我不能检索一个具有泛型定义的类型,或者我能做些什么来实现这一点 我的例子是: [System.Collections.Generic.List`1].FullName --> Outputs: System.Collections.Generic.List`1 但两者都有 [System.Type]::GetType("System.Collections.Generic.List`1") [System.Type]::GetType("System.Collecti

我想知道为什么我不能检索一个具有泛型定义的类型,或者我能做些什么来实现这一点

我的例子是:

[System.Collections.Generic.List`1].FullName

--> Outputs: System.Collections.Generic.List`1

但两者都有

[System.Type]::GetType("System.Collections.Generic.List`1")

[System.Type]::GetType("System.Collections.Generic.List`1, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")

不要输出任何内容,即使可以在mscorlib中找到列表的类型。有人能告诉我如何按名称查找此类型和其他泛型类型吗?

`
是PowerShell中的转义字符,您需要以字符串形式转义它。 这两种方法中的任何一种都会起作用:

[System.Type]::GetType("System.Collections.Generic.List``1")
[System.Type]::GetType('System.Collections.Generic.List`1')

[System.Collections.Generic.List`1].GetType()是的,但由于某种原因,我将类型名称设置为字符串:(因此,唯一可能的选择是创建类型并将类型定义保存在变量中?但老实说,我认为根本没有办法通过名称找到它。
[System.Type]::GetType("System.Collections.Generic.List``1")
[System.Type]::GetType('System.Collections.Generic.List`1')