예제 #1
0
        public static IMapper <T> Parse <T>(IDataRecord template)
        {
            var type      = typeof(T);
            var fieldType = template.GetFieldType(0);

            if (type.IsAssignableFrom(fieldType))
            {
                return(Mappers.Direct <T>());
            }

            if (ReflectionUtils.IsAnonymousType(type))
            {
                return(new AnonymousObjectMapper <T>(template));
            }

            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                return((IMapper <T>)ParseNullableTypeMapper <T>(template));
            }

            if (type.IsEnum)
            {
                return(EnumMapper <T> .Instance);
            }

            if (typeof(IConvertible).IsAssignableFrom(type))
            {
                return(Mappers.Convertible <T>());
            }

            return(new ObjectMapper <T>(template));
        }