Browse Source

Compatible with .NET CORE

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
963c7de85d
  1. 61
      Src/Asp.Net/SqlSugar/CompatibleNetCore/CompatibleExtensions.cs
  2. 8
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

61
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();
}
}
}

8
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)

Loading…
Cancel
Save