我希望提供运行代码的服务器上可用的 System.Net.SecurityProtocolType 的下拉列表(服务器不同)
所以我希望做相当于
的工作...System.Enum.GetValues(System.Net.SecurityProtocolType)
(这抱怨“SecurityProtocolType 是枚举类型,不能用作表达式”)
这是一个关于如何对内置枚举执行此操作的更广泛的问题,因此我希望避免不可避免的情况 - 为什么您需要评估 SecurityProtocolType 答案。
理想情况下,我想要 VB.NET 解决方案,但对 C# 会很满意
正如其他人在评论中所说,您需要使用类型:
System.Enum.GetValues(typeof(System.Net.SecurityProtocolType))
如果您想要显示名称,则需要使用反射,例如:
@foreach (SecurityProtocolType type in Enum.GetValues(typeof(SecurityProtocolType))) {
var displayNameAttribute = type.GetType().GetMember(type.ToString())
.First()
.GetCustomAttribute<DisplayAttribute>();
var displayName = displayNameAttribute?.Name ?? type.ToString();
}