{"id":231,"date":"2011-08-14T16:41:49","date_gmt":"2011-08-14T16:41:49","guid":{"rendered":"http:\/\/strikelimit.co.uk\/m\/?p=231"},"modified":"2011-08-15T08:01:15","modified_gmt":"2011-08-15T08:01:15","slug":"c-listing-enumerations-with-their-properties","status":"publish","type":"post","link":"http:\/\/strikelimit.co.uk\/m\/?p=231","title":{"rendered":"C# &#8211; Listing enumerations with their properties"},"content":{"rendered":"<p>A small supplementary post about how to list every element of an enumeration alongside a property derived from a method that uses the element.<\/p>\n<p>I encountered this problem when wanting to list the various biomes in my World Generation project alongside the color they were represented by on the terrain. The first step was to convert the enumeration to an array of strings (listing each of the enum&#8217;s elements), which can easily be achieved with the following code:<\/p>\n<pre lang=\"CSHARP\">string[] biomes = Enum.GetNames(typeof(BiomeType));<\/pre>\n<p>Where <em>BiomeType <\/em>was the name of the enum. This was all very well to write as a list to the screen but now I wanted to be able to covert each of the elements back from its string form to its enumeration form, in order to pass it through the method that returns the terrain color. After some investigation I found the following method to achieve this:<\/p>\n<pre lang=\"CSHARP\">(BiomeType)Enum.Parse(typeof(BiomeType), biome))<\/pre>\n<p>Again where <em>BiomeType<\/em> was the name of the enumeration and <em>biome <\/em>was the element in string form.<\/p>\n<p>Hopefully this short post will help at least one person at some point!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A small supplementary post about how to list every element of an enumeration alongside a property derived from a method that uses the element. I encountered this problem when wanting to list the various biomes in my World Generation project alongside the color they were represented by on the terrain. The first step was to &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/strikelimit.co.uk\/m\/?p=231\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[4,21,26,27,28,29,5],"_links":{"self":[{"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=\/wp\/v2\/posts\/231"}],"collection":[{"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=231"}],"version-history":[{"count":5,"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":236,"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=\/wp\/v2\/posts\/231\/revisions\/236"}],"wp:attachment":[{"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/strikelimit.co.uk\/m\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}