Development – Leet 4 Life

Software Development Code Samples and More

Skip to: Content | Sidebar | Footer

Tag: Enumeration

Converting a Value Back to an Enumeration

23 March, 2012 | C#. NET | By: Michael Merrell

Stored enumeration values need a way to be converted back to to their enumeration type.  In a previous post I go into detail on how to get the values on an enumeration and return them in a usable data format.  This is great if we want to store the value in the database, but when you pull the value back out you need to have a way to convert it back into something usable.   There are two methods defined below, both take in a Type parameter and then a value parameter.  The first method below also takes in a default value in [Read More…]

Using an Enumeration as a Data Source

12 March, 2012 | C#. NET | By: Michael Merrell

Enumerations have many uses but one use that doesn’t get much attention is using an enumeration as a data source.   I have written two methods that will take in an enumeration (Either Type name as string or the actual Type) and then return a dictionary of all the name/value pairs.  All enumerations have a numerical value, whether the actual values are defined specifically or automatically populated is up to the developer.  A long is used here as all values that can be defined for an enumeration will convert to a long value.  However, you can also assign an integer or byte value [Read More…]