ExtensionsUtil.cs 882 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace EdjCase.JsonRpc.Core.Utilities
  5. {
  6. public static class TypeExtensions
  7. {
  8. /// <summary>
  9. /// Determines if the type is a number
  10. /// </summary>
  11. /// <param name="type">Type of the object</param>
  12. /// <param name="includeInteger">Includes a check for whole number types. Defaults to true</param>
  13. /// <returns>True if the type is a number, otherwise False</returns>
  14. public static bool IsNumericType(this Type type, bool includeInteger = true)
  15. {
  16. if (includeInteger)
  17. {
  18. return type == typeof(long)
  19. || type == typeof(int)
  20. || type == typeof(short)
  21. || type == typeof(float)
  22. || type == typeof(double)
  23. || type == typeof(decimal);
  24. }
  25. else
  26. {
  27. return type == typeof(float)
  28. || type == typeof(double)
  29. || type == typeof(decimal);
  30. }
  31. }
  32. }
  33. }