12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using Ant.DbExpressions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- namespace Ant.Oracle
- {
- internal static class Utils
- {
- public static void CheckNull(object obj, string paramName = null)
- {
- if (obj == null)
- throw new ArgumentNullException(paramName);
- }
- public static bool IsNullable(Type type)
- {
- Type unType;
- return IsNullable(type, out unType);
- }
- public static bool IsNullable(Type type, out Type unType)
- {
- unType = Nullable.GetUnderlyingType(type);
- return unType != null;
- }
- public static Type GetUnderlyingType(Type type)
- {
- Type unType;
- if (!IsNullable(type, out unType))
- unType = type;
- return unType;
- }
- 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 Dictionary<TKey, TValue> Clone<TKey, TValue>(Dictionary<TKey, TValue> source, IEqualityComparer<TKey> comparer = null)
- {
- Dictionary<TKey, TValue> ret;
- if (comparer == null)
- ret = new Dictionary<TKey, TValue>(source.Count);
- else
- ret = new Dictionary<TKey, TValue>(source.Count, comparer);
- foreach (var kv in source)
- {
- ret.Add(kv.Key, kv.Value);
- }
- return ret;
- }
- public static string ToMethodString(this MethodInfo method)
- {
- StringBuilder sb = new StringBuilder();
- ParameterInfo[] parameters = method.GetParameters();
- for (int i = 0; i < parameters.Length; i++)
- {
- ParameterInfo p = parameters[i];
- if (i > 0)
- sb.Append(",");
- string s = null;
- if (p.IsOut)
- s = "out ";
- sb.AppendFormat("{0}{1} {2}", s, p.ParameterType.Name, p.Name);
- }
- return string.Format("{0}.{1}({2})", method.DeclaringType.Name, method.Name, sb.ToString());
- }
- }
- }
|