新框架PC后端代码(祈禧6月初版本)
南骏 池
4 天以前 72449a1b8699b65712e57fba8abce5a8240e9465
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
namespace Gs.Toolbox.ApiCore.Common.Helper;
 
public static class TypeHelper
{
    public static bool IsPrimitiveExtended(Type type,
        bool includeNullables = true, bool includeEnums = false)
    {
        if (IsPrimitiveExtendedInternal(type, includeEnums)) return true;
 
        if (includeNullables && IsNullable(type) &&
            type.GenericTypeArguments.Any())
            return IsPrimitiveExtendedInternal(type.GenericTypeArguments[0],
                includeEnums);
 
        return false;
    }
 
    public static bool IsNullable(Type type)
    {
        return type.IsGenericType &&
               type.GetGenericTypeDefinition() == typeof(Nullable<>);
    }
 
    private static bool IsPrimitiveExtendedInternal(Type type,
        bool includeEnums)
    {
        if (type.IsPrimitive) return true;
 
        if (includeEnums && type.IsEnum) return true;
 
        return type == typeof(string) ||
               type == typeof(decimal) ||
               type == typeof(DateTime) ||
               type == typeof(DateTimeOffset) ||
               type == typeof(TimeSpan) ||
               type == typeof(Guid);
    }
}