title: Enum Casting With a Variable
body: <p>I was hoping to get some help with this. I need a function that can take in a string that is a key for a dictionary and an enum type that is has to be cast to.</p>
  
  <p>The dictionary key will be a number that corresponds to an enum. I need to know how to cast the int into an enum where the enum is variable.</p>
  
  <p>Here is the function as I have it written. This might be more clear than my explanation.</p>
  
  <pre><code>string GetEnum(string keyName, Enum enumType)
  {
      var defaultOut = "";
      Model.Form.TryGetValue(keyName, out defaultOut);
      if(defaultOut != ""){
          return EnumDescriptionUtility.GetDescription((enumType)Convert.ToInt32(defaultOut));            
      }
      else{
          return defaultOut;    
      } 
  }
  </code></pre>
  
  <p>I have used most of this code before. the difference before was that enumType was hard coded to the actual enum. I want to offload all that repetition to a function.</p>
  
  <p>Any help is appreciated.</p>