From 963c7de85dbebd7e3b283e73539164ffe86b5429 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 1 Jul 2017 12:57:28 +0800 Subject: [PATCH] Compatible with .NET CORE --- .../CompatibleNetCore/CompatibleExtensions.cs | 61 +++++++++++++++++++ .../ExpressionsToSql/Common/ExpressionTool.cs | 8 +-- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/CompatibleNetCore/CompatibleExtensions.cs b/Src/Asp.Net/SqlSugar/CompatibleNetCore/CompatibleExtensions.cs index 4845b9106..df960f681 100644 --- a/Src/Asp.Net/SqlSugar/CompatibleNetCore/CompatibleExtensions.cs +++ b/Src/Asp.Net/SqlSugar/CompatibleNetCore/CompatibleExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; namespace SqlSugar @@ -14,5 +15,65 @@ namespace SqlSugar { return typeInfo; } + + public static Type[] GetGenericArguments(this Type type) + { + var reval = type.GetTypeInfo().GetGenericArguments(); + return reval; + } + public static bool IsGenericType(this Type type) + { + var reval = type.GetTypeInfo().IsGenericType; + return reval; + } + public static PropertyInfo[] GetProperties(this Type type) + { + var reval = type.GetTypeInfo().GetProperties(); + return reval; + } + public static PropertyInfo GetProperty(this Type type, string name) + { + var reval = type.GetTypeInfo().GetProperty(name); + return reval; + } + + public static FieldInfo GetField(this Type type, string name) + { + var reval = type.GetTypeInfo().GetField(name); + return reval; + } + + public static bool IsEnum(this Type type) + { + var reval = type.GetTypeInfo().IsEnum; + return reval; + } + + public static MethodInfo GetMethod(this Type type, string name) + { + var reval = type.GetTypeInfo().GetMethod(name); + return reval; + } + public static MethodInfo GetMethod(this Type type, string name, Type[] types) + { + var reval = type.GetTypeInfo().GetMethod(name, types); + return reval; + } + public static ConstructorInfo GetConstructor(this Type type, Type[] types) + { + var reval = type.GetTypeInfo().GetConstructor(types); + return reval; + } + + public static bool IsValueType(this Type type) + { + return type.GetTypeInfo().IsValueType; + } + + + public static bool IsEntity(this Type type) + { + return type.GetTypeInfo().IsClass(); + } } } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs index ed8d4a3e6..b0c436ad4 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs @@ -111,7 +111,7 @@ namespace SqlSugar object reval = null; FieldInfo field = (FieldInfo)memberExpr.Member; reval = field.GetValue(memberExpr.Member); - if (reval != null && reval.GetType().IsClass && reval.GetType() != ExpressionConst.StringType) + if (reval != null && reval.GetType().IsClass() && reval.GetType() != ExpressionConst.StringType) { var fieldName = memberExpr.Member.Name; var proInfo = reval.GetType().GetProperty(fieldName); @@ -137,7 +137,7 @@ namespace SqlSugar object reval = null; PropertyInfo pro = (PropertyInfo)memberExpr.Member; reval = pro.GetValue(memberExpr.Member, null); - if (reval != null && reval.GetType().IsClass && reval.GetType() != ExpressionConst.StringType) + if (reval != null && reval.GetType().IsClass() && reval.GetType() != ExpressionConst.StringType) { var fieldName = memberExpr.Member.Name; var proInfo = reval.GetType().GetProperty(fieldName); @@ -161,7 +161,7 @@ namespace SqlSugar public static object DynamicInvoke(Expression expression) { object value = Expression.Lambda(expression).Compile().DynamicInvoke(); - if (value != null && value.GetType().IsClass && value.GetType() != ExpressionConst.StringType) + if (value != null && value.GetType().IsClass() && value.GetType() != ExpressionConst.StringType) { value = Expression.Lambda(expression).Compile().DynamicInvoke(); } @@ -180,7 +180,7 @@ namespace SqlSugar public static bool IsEntity(Type type) { - return type.IsClass && type!=ExpressionConst.StringType; + return type.IsClass() && type!=ExpressionConst.StringType; } public static bool IsValueType(Type type)