在Powershell中使用名称空间
回答这个问题的时候想一想。 如何避免完全限定名称空间中的每种类型的需要? 这是真的,真的很乏味写System.Security.Cryptography.X509Certificates.X509Store的,而不是X509Store或[System.Security.Cryptography.X509Certificates.StoreName]::My代替[StoreName]::My。 在C#中,您有using指令... Powershell呢? 编辑1-适用于以下类型: $ns = "System.Security.Cryptography.X509Certificates" $store = New-Object "$ns.X509Store"(StoreName,StoreLocation) New-Object采用字符串文字作为类型定义,因此可以以编程方式构建。 编辑2-这适用于用作参数的枚举成员: $store = New-Object "$ns.X509Store"("My","LocalMachine") 其中“我的” [System.Security.Cryptography.X509Certificates.StoreName]::My和“本地机器”的位置[System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine。 如果将文字名称放在期望枚举成员的位置,则会自动将其转换为枚举成员。