小编cor*_*sol的帖子

在 PowerShell 中使用枚举类型

我在 powershell 中有点新(预期消息开始:))。我无法在这里或其他地方找到我的问题的答案,所以有人可以帮助我吗?

例如,我们想使用一些在 .NET 库中声明的枚举。我们如何在 .NET 中使用它?就像:

using System.Data.SqlClient;

public class Test {
   var x = SortOrder.Ascending;
}
Run Code Online (Sandbox Code Playgroud)

如果我需要在 powershell 中使用它,据我所知,我需要编写如下内容:

$x = [System.Data.SqlClient.SortOrder]::Ascending
Run Code Online (Sandbox Code Playgroud)

所以,问题是,是否有可能在 powershell 中使用类似 C# 中的“使用”来将语法缩短为类似:$sortOrder.Ascending[SortOrder]::Ascending

powershell enums powershell-2.0 powershell-3.0

3
推荐指数
1
解决办法
511
查看次数