In previous articles Get enumeration items as a list in C# and Populate dropdown with enumeration items in ASP.NET Core we that saw how to get enumeration items as a collection to bind it to data controls like dropdown etc.
In this article we will see that how can we get the description given as an attribute with an item. We may need this information on various places, say we have listing of users and we need to show each user’s status but in a descriptive way.

Here is our example enumeration:

  enum UserStatus
    {
        [Description("Pending Verification")]
        PendingVerification = 1,
        [Description("Pending Admin Approval")]
        PendingAdminApproval = 2,
        [Description("Active")]
     
 ...  read more

We can bind a dropdown with enumeration items without creating a look up table.

In Get enumeration items as a list in C# article we saw that how we can get enumeration items as a list to bind it to a data control.

Here is the enumeration we have been working with:

 enum UserStatus
    {
        [Description("Pending Verification")]
        PendingVerification = 1,
        [Description("Pending Admin Approval")]
        PendingAdminApproval = 2,
        [Description("Active")]
      
 ...  read more

While developing Angular applications in Visual Studio 2019 & Visual Studio Code following compile time error is shown:

TS1219 Experimental support for decorators is a feature that is subject to change in a future release. Specify ‘–experimentalDecorators’ to remove this warning.

Visual Studio Fix:

I am using Visual Studio 2019 and fixed the issue in it, it might work in other versions as well.

Add the following lines in .csproj file:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">    
    <TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators>
    <TypeScriptEmitDecoratorMetadata>True</TypeScriptEmitDecoratorMetadata>
 ...  read more

Microsoft Office 365 will no more support to connect using TLS1.0 and TLS1.1, please read it here.

All the browser-server or client-server applications must use TLS1.2 or later to be able communicate with Office 365 services.

Here is how we can implement it in C# to connect using TLS1.2, put the following line of code either in the constructor of the class which you are using to communicate with the Office 365 services or in the method directly:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;          

As more and more service providers like PayPal and others or switching to support TLS1.2 only, you can put above line of code before calling any web service or API which supports TLS1.2 only.

If your service provider supports more than one security protocol you can mention it like below:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

If you are using .NET Framework version older than 4.5 then use the following code:

System.Net.ServicePointManager.SecurityProtocol
 ...  read more