You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using System; using System.Data; using System.Linq; using System.Reflection; using System.Text.RegularExpressions;
namespace SqlSugar { public class UtilMethods { internal static Type GetUnderType(Type oldType) { var type = Nullable.GetUnderlyingType(oldType); return type==null ? oldType : type; }
internal static Type GetUnderType(PropertyInfo propertyInfo, ref bool isNullable) { var unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); isNullable = unType != null; unType = unType ?? propertyInfo.PropertyType; return unType; }
internal static Type GetUnderType(PropertyInfo propertyInfo) { var unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); unType = unType ?? propertyInfo.PropertyType; return unType; }
internal static bool IsNullable(PropertyInfo propertyInfo) { var unType = Nullable.GetUnderlyingType(propertyInfo.PropertyType); return unType != null; }
internal static T IsNullReturnNew<T>(T returnObj) where T : new() { if (returnObj.IsNullOrEmpty()) { returnObj = new T(); } return returnObj; }
internal static T ChangeType<T>(T obj, Type type) { return (T)Convert.ChangeType(obj, type); }
internal static T ChangeType<T>(T obj) { return (T)Convert.ChangeType(obj, typeof(T)); }
internal static void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex) { if (appendSql.HasValue() && parameters.HasValue()) { foreach (var parameter in parameters.OrderByDescending(it => it.ParameterName.Length)) { //Compatible with.NET CORE parameters case
var name = parameter.ParameterName; var newName = name + addIndex; appendSql = appendSql.Replace(name, newName); parameter.ParameterName = newName; } } }
internal static string GetPackTable(string sql, string shortName) { return string.Format(" ({0}) {1} ", sql, shortName); }
internal static string GetParenthesesValue(string dbTypeName) { if (Regex.IsMatch(dbTypeName, @"\(.+\)")) { dbTypeName = Regex.Replace(dbTypeName, @"\(.+\)", ""); } dbTypeName = dbTypeName.Trim(); return dbTypeName; }
internal static T GetOldValue<T>(T value, Action action) { action?.Invoke(); return value; } } }
|