我希望提供运行代码的服务器上可用的 System.Net.SecurityProtocolType 的下拉列表(服务器不同)
所以我希望做相当于
的工作...System.Enum.GetValues(System.Net.SecurityProtocolType)
or
...System.Enum.GetValues(TypeOf (System.Net.SecurityProtocolType))
...
(两者都抱怨“SecurityProtocolType 是 Enum 类型,不能用作表达式”)
理想情况下,我想要 VB.NET 解决方案,但对 C# 会很满意
正如其他人在评论中所说,您需要使用类型:
System.Enum.GetValues(typeof(System.Net.SecurityProtocolType))
这将为您提供文本值(SystemDefault、Ssl3、Tls 等)。如果你有想要显示的自定义显示属性,你需要使用反射,比如:
@foreach (SecurityProtocolType type in Enum.GetValues(typeof(SecurityProtocolType))) {
var displayNameAttribute = type.GetType().GetMember(type.ToString())
.First()
.GetCustomAttribute<DisplayAttribute>();
var displayName = displayNameAttribute?.Name ?? type.ToString();
}