public static void LoadConverters <TContext>(this IResourceMapper <TContext> resourceMapper, Type type, params Func <MethodInfo, bool>[] verify) { foreach (var methodInfo in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.ExactBinding).Where(m => m.IsPublic && m.ReturnType != null && m.IsStatic && m.GetParameters().Length == 1 && verify.Aggregate(true, (seed, check) => seed && check(m)))) { var fromType = methodInfo.GetParameters()[0].ParameterType; var toType = methodInfo.ReturnType; var info = methodInfo; resourceMapper.ConvertUsing(fromType, toType, from => info.Invoke(null, new [] { from })); } }
public void Convert_EnumToIntBehavesCorrectly() { _resourceMapper.ConvertUsing((CustomEnum1 v) => (int)v); _resourceMapper.InitializeMap(); Assert.AreEqual(1, _resourceMapper.Map <CustomEnum1, int>(CustomEnum1.Value2, null)); }