SqlSugar/Src/Asp.Net/SqlSugar/Utilities/PubMethod.cs

60 lines
1.6 KiB
C#
Raw Normal View History

2017-01-07 21:54:51 +08:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
namespace SqlSugar
{
public class PubMethod
{
2017-07-09 19:12:41 +08:00
internal static Type GetUnderType(Type oldType)
{
Type type = Nullable.GetUnderlyingType(oldType);
return type==null ? oldType : type;
}
2017-01-07 21:54:51 +08:00
internal static Type GetUnderType(PropertyInfo propertyInfo, ref bool isNullable)
{
Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType);
isNullable = unType != null;
unType = unType ?? propertyInfo.PropertyType;
return unType;
}
2017-06-01 14:26:49 +08:00
internal static Type GetUnderType(PropertyInfo propertyInfo)
{
Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType);
unType = unType ?? propertyInfo.PropertyType;
return unType;
}
2017-06-12 15:41:57 +08:00
internal static bool IsNullable(PropertyInfo propertyInfo)
{
Type unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType);
2017-07-09 19:12:41 +08:00
return unType != null;
2017-06-12 15:41:57 +08:00
}
2017-07-09 19:12:41 +08:00
internal static T IsNullReturnNew<T>(T returnObj) where T : new()
2017-01-07 21:54:51 +08:00
{
if (returnObj.IsNullOrEmpty())
{
returnObj = new T();
}
return returnObj;
}
2017-07-09 19:12:41 +08:00
internal static T ChangeType<T>(T obj, Type type)
2017-01-07 21:54:51 +08:00
{
return (T)Convert.ChangeType(obj, type);
}
internal static T ChangeType<T>(T obj)
{
return (T)Convert.ChangeType(obj, typeof(T));
}
}
}