Conversion.SimpleTypes.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text;
  6. using System.Web;
  7. namespace Utilities
  8. {
  9. public partial class Conversion
  10. {
  11. public static int ToInt32(object obj)
  12. {
  13. return ToInt32(obj, 0);
  14. }
  15. public static int ToInt32(object obj, int defaultValue)
  16. {
  17. int result = defaultValue;
  18. if (obj != null)
  19. {
  20. try
  21. {
  22. result = Convert.ToInt32(obj);
  23. }
  24. catch
  25. {}
  26. }
  27. return result;
  28. }
  29. public static long ToInt64(object obj)
  30. {
  31. return ToInt64(obj, 0);
  32. }
  33. public static long ToInt64(object obj, long defaultValue)
  34. {
  35. long result = defaultValue;
  36. if (obj != null)
  37. {
  38. try
  39. {
  40. result = Convert.ToInt64(obj);
  41. }
  42. catch
  43. { }
  44. }
  45. return result;
  46. }
  47. }
  48. }