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')