Utils.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Ant.DbExpressions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Ant.SqlServer
  7. {
  8. internal static class Utils
  9. {
  10. public static void CheckNull(object obj, string paramName = null)
  11. {
  12. if (obj == null)
  13. throw new ArgumentNullException(paramName);
  14. }
  15. public static bool IsNullable(Type type)
  16. {
  17. Type unType;
  18. return IsNullable(type, out unType);
  19. }
  20. public static bool IsNullable(Type type, out Type unType)
  21. {
  22. unType = Nullable.GetUnderlyingType(type);
  23. return unType != null;
  24. }
  25. public static Type GetUnderlyingType(Type type)
  26. {
  27. Type unType;
  28. if (!IsNullable(type, out unType))
  29. unType = type;
  30. return unType;
  31. }
  32. public static bool AreEqual(object obj1, object obj2)
  33. {
  34. if (obj1 == null && obj2 == null)
  35. return true;
  36. if (obj1 != null)
  37. {
  38. return obj1.Equals(obj2);
  39. }
  40. if (obj2 != null)
  41. {
  42. return obj2.Equals(obj1);
  43. }
  44. return object.Equals(obj1, obj2);
  45. }
  46. public static Dictionary<TKey, TValue> Clone<TKey, TValue>(Dictionary<TKey, TValue> source, IEqualityComparer<TKey> comparer = null)
  47. {
  48. Dictionary<TKey, TValue> ret;
  49. if (comparer == null)
  50. ret = new Dictionary<TKey, TValue>(source.Count);
  51. else
  52. ret = new Dictionary<TKey, TValue>(source.Count, comparer);
  53. foreach (var kv in source)
  54. {
  55. ret.Add(kv.Key, kv.Value);
  56. }
  57. return ret;
  58. }
  59. }
  60. }