eswartechraq / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Provide support for custom enum parse #180

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Would it be possible to provide a mechanism allowing for a custom enum parse 
method? SqlMapper (4.0) provides the default implementation of enum parse 
around line 2750 as:

static readonly MethodInfo enumParse = typeof(Enum).GetMethod("Parse", new 
Type[] { typeof(Type), typeof(string), typeof(bool) })

We are currently modifying the "static readonly MethodInfo enumParse" and 
removing the readonly modifier. This allows us to set our own custom enum 
parser by matching the signature Dapper is expecting with the DotNet Enum.Parse 
method:

static partial class SqlMapper
{
    internal static void SetEnumParse( Func<Type, string, bool, object> func )
    {
        enumParse = func.Method;
    }
}

Is this something you would consider adding support for with Dapper? Not 
necessarily as we've implemented, just as long as there was a way to override 
the default Dapper implementation.

Thanks!

Original issue reported on code.google.com by kind...@gmail.com on 17 Jun 2014 at 4:42