Just Simply Code

Another developer blog

  • Home
  • About
  • Register
  • Policy

Enum

Custom JSON converter to de-serialise Enum description value to Enum value

1 August 2021 / Leave a Comment

It’s common to have description attributes on Enum types. This allows adding a longer description string for each Enum value. In one of my recent projects, I have a Web API that needs to accept this description value from the JSON request body and map to the correct Enum value. In this post, I’m going … [Read more…]

Posted in: Uncategorised Tagged: Enum, Json, Json Converter, Json Deserialisation, Json Serialisation

Checking if generic parameter is enum for nullable type

13 September 2020 / Leave a Comment

I come across a bug in a method we have in our projects at work. The method takes a generic type and then it checks if the type is enum before it applies further logic to it. If the type is not an enum, it will throw an ArgumentException. The method is similar to the … [Read more…]

Posted in: Uncategorised Tagged: Enum, Extension methods, Nullable

Helper method to get enum list with custom ordering

30 March 2019 / Leave a Comment

I have a client generated enum class with values already defined. I have to populate a dropdown list with all the enum values with a different order than the order they are declared in. First, I thought its as simple as just rearranging the order they are declared in to the order I need and … [Read more…]

Posted in: Uncategorised Tagged: Enum, Extension Method

Keeping enums as look up tables in DB vs keeping them in code

20 October 2018 / Leave a Comment

I’ve worked in teams that do enums in 2 different ways. One is storing enums as lookup tables in the DB. The other is to keep it in code. I’m going to show how they are used and my preferred way. Disclaimer, this is just a personal preference. There are pros and cons in both … [Read more…]

Posted in: Uncategorised Tagged: Enum

Enum extension method to get value from Description attribute.

10 July 2016 / Leave a Comment

I’m going to show how to get the value from the Description attribute on each enum. We have the following enum as an example public enum MonthOfYear { [Description(“First month of the year”)] January, [Description(“Second month of the year”)] February, [Description(“Third month of the year”)] March // … and so on } If you use … [Read more…]

Posted in: Uncategorised Tagged: Enum, Extension Method

Storing enum as string in Entity Framework 6

17 January 2016 / 5 Comments

I’m working on a side project where I use Entity Framework 6 for my data layer. I need to store an enum in the database as string rather than integer. This is because I don’t like having enum columns in database without meaningful value. Plus this also makes it easier to know what that enum … [Read more…]

Posted in: Uncategorised Tagged: Entity Framework 6, Enum

Search Posts

Recent Posts

  • Override IHttpRequestBodyDetectionFeature.CanHaveBodyOverride value in .NET Core Web API
  • Allow empty request body in PUT and POST HTTP requests in .NET Core Web API
  • Modify request body with middleware in .NET Core Web API
  • Running MS Orleans on AWS ECS
  • Respect leading and trailing spaces when querying SQL Server
Support my blog here!Support my blog!

Archives

  • July 2024
  • June 2024
  • July 2023
  • April 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • October 2017
  • September 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • July 2016
  • June 2016
  • March 2016
  • February 2016
  • January 2016

Copyright © 2025 Just Simply Code.

Me WordPress Theme by themehall.com