title: Dynamic enum converter
body: <p>I want to create a dynamic 2-way-converter for all possible enums in my application.</p>
  
  <p>I don't want to have to create a converter for each enum, I want to create one converter that provides converting from enum to byte and from byte to enum vice versa.</p>
  
  <p>How can I get there? My approach is already 2-way but requires a static cast <strong>(MyEnum)</strong> in the code:</p>
  
  <pre><code>public class MyEnumConverter : MarkupExtension, IValueConverter 
          {
          public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture) {
              return (MyEnum)value;
          }
  
          public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) {
              return (byte)value;
          }
  
          public override object ProvideValue(System.IServiceProvider serviceProvider) {
              return this;
          }
      }
  </code></pre>