1. 程式人生 > >判斷是不是C#內建型別

判斷是不是C#內建型別

private static bool IsBulitinType(Type type)
{
    return (type == typeof(object) || Type.GetTypeCode(type) != TypeCode.Object);
}

在網上看到老外寫的這個,但是個人認為這個是有問題的,先記錄下,後期驗證

驗證了下,應該是沒有問題的

我接上面的方法寫了一個判斷是不是自定義型別

private static bool IsCustomType(Type type)
        {
            return (type !=typeof(object) && Type.GetTypeCode(type) == TypeCode.Object);
        }


判斷是不是集合

bool IsEnumerableType(Type type)
{
    return (type.GetInterface("IEnumerable") != null);
}