﻿namespace NetCreditHub.Extensions
{
    using System;
    using System.Reflection;
    using System.Collections.Generic;

    internal static class TypeExtensions
    {
        public static PropertyInfo GetProperty(this Type type, string name)
        {
            return type.GetProperty(name);
        }

        public static bool IsGenericType(this Type type)
        {
            return type.IsGenericType;
        }

        public static bool IsEnum(this Type type)
        {
            return type.IsEnum;
        }

        public static bool IsValueType(this Type type)
        {
            return type.IsValueType;
        }

        public static bool IsBool(this Type type)
        {
            return type == typeof(bool);
        }

        public static bool IsIntType<T>(List<T> entities)
        {
            if (entities.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(entities), "列表不能为空.");
            }

            var entity = entities[0];
            var entityTypeName = entity.GetType().Name.ToLower();

            return entityTypeName.StartsWith("int");
        }
    }
}