Skip to content

Instantly share code, notes, and snippets.

@af4jm
Last active August 1, 2018 16:04
Show Gist options
  • Save af4jm/c1f1da0997f0c27990b3ee0b9646045e to your computer and use it in GitHub Desktop.
Save af4jm/c1f1da0997f0c27990b3ee0b9646045e to your computer and use it in GitHub Desktop.
make AutoMapper IDataReader conversion work with SmartEnum
namespace MyCompany.MyApp.Core.Enums
{
using Ardalis.SmartEnum;
using AutoMapper;
public abstract class SmartEnumTypeConverter<TValue, TEnum> : ITypeConverter<TValue, TEnum>
where TEnum : SmartEnum<TEnum, TValue>
{
protected SmartEnumTypeConverter()
{
}
public TEnum Convert(TValue source, TEnum destination, ResolutionContext context)
{
return (TEnum)source;
}
}
}
namespace MyCompany.MyApp.Core.Enums
{
public class TestEnumTypeConverter : SmartEnumTypeConverter<int, TestEnum>
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment