123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using Ant.Common;
- using Ant.DbExpressions;
- using Ant.ORM;
- using Ant.Query;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- namespace Ant.Utility
- {
- static class OrmUtils
- {
- public static void CheckNull(object obj, string paramName = null)
- {
- if (obj == null)
- throw new ArgumentNullException(paramName);
- }
- public static bool AreEqual(object obj1, object obj2)
- {
- if (obj1 == null && obj2 == null)
- return true;
- if (obj1 != null)
- {
- return obj1.Equals(obj2);
- }
- if (obj2 != null)
- {
- return obj2.Equals(obj1);
- }
- return object.Equals(obj1, obj2);
- }
- public static string GenerateUniqueColumnAlias(DbSqlQueryExpression sqlQuery, string defaultAlias = UtilConstants.DefaultColumnAlias)
- {
- string alias = defaultAlias;
- int i = 0;
- while (sqlQuery.ColumnSegments.Any(a => string.Equals(a.Alias, alias, StringComparison.OrdinalIgnoreCase)))
- {
- alias = defaultAlias + i.ToString();
- i++;
- }
- return alias;
- }
- public static Dictionary<TKey, TValue> Clone<TKey, TValue>(Dictionary<TKey, TValue> source)
- {
- Dictionary<TKey, TValue> ret = Clone<TKey, TValue>(source, source.Count);
- return ret;
- }
- public static Dictionary<TKey, TValue> Clone<TKey, TValue>(Dictionary<TKey, TValue> source, int capacity)
- {
- Dictionary<TKey, TValue> ret = new Dictionary<TKey, TValue>(capacity);
- foreach (var kv in source)
- {
- ret.Add(kv.Key, kv.Value);
- }
- return ret;
- }
- public static List<T> Clone<T>(List<T> source, int? capacity = null)
- {
- List<T> ret = new List<T>(capacity ?? source.Count);
- ret.AddRange(source);
- return ret;
- }
- public static List<T> CloneAndAppendOne<T>(List<T> source, T t)
- {
- List<T> ret = new List<T>(source.Count + 1);
- ret.AddRange(source);
- ret.Add(t);
- return ret;
- }
- public static DbJoinType AsDbJoinType(this JoinType joinType)
- {
- switch (joinType)
- {
- case JoinType.InnerJoin:
- return DbJoinType.InnerJoin;
- case JoinType.LeftJoin:
- return DbJoinType.LeftJoin;
- case JoinType.RightJoin:
- return DbJoinType.RightJoin;
- case JoinType.FullJoin:
- return DbJoinType.FullJoin;
- default:
- throw new NotSupportedException();
- }
- }
- public static Type GetFuncDelegateType(Type[] typeArguments)
- {
- int parameters = typeArguments.Length;
- Type funcType = null;
- switch (parameters)
- {
- case 3:
- funcType = typeof(Func<,,>);
- break;
- case 4:
- funcType = typeof(Func<,,,>);
- break;
- case 5:
- funcType = typeof(Func<,,,,>);
- break;
- case 6:
- funcType = typeof(Func<,,,,,>);
- break;
- default:
- throw new NotSupportedException();
- }
- return funcType.MakeGenericType(typeArguments);
- }
- }
- }
|