How do I get a list of possible names/values from System.Net.SecurityProtocolType

101 views Asked by At

I wish to present a drop down list of the System.Net.SecurityProtocolType available on the server that the code is running from (The servers are different)

So I wish to do the working equivalent of

...System.Enum.GetValues(System.Net.SecurityProtocolType)

or

...System.Enum.GetValues(TypeOf (System.Net.SecurityProtocolType))

...

(both of these complain "SecurityProtocolType is an Enum type and cannot be used as an expression")

Visual Studio error shown

Ideally I'd like a VB.NET solution but would be happy with C#

1

There are 1 answers

5
Michael G On

As others said in comments, you need to use the type:

System.Enum.GetValues(typeof(System.Net.SecurityProtocolType))

that will give you the text values (SystemDefault, Ssl3, Tls, etc..). If you have custom display attributes you want to display, you need to use reflection, something like:

 @foreach (SecurityProtocolType type in Enum.GetValues(typeof(SecurityProtocolType))) {
 var displayNameAttribute = type.GetType().GetMember(type.ToString())
 .First()
 .GetCustomAttribute<DisplayAttribute>();
 var displayName = displayNameAttribute?.Name ?? type.ToString();
}