RpcUtil.cs 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. namespace JsonRPC4.Router.Utilities
  6. {
  7. public class RpcUtil
  8. {
  9. public static bool TypesMatch(object value, Type type)
  10. {
  11. Type underlyingType = Nullable.GetUnderlyingType(type);
  12. if (underlyingType != null)
  13. {
  14. type = underlyingType;
  15. }
  16. return value?.GetType() == type;
  17. }
  18. public static bool NamesMatch(ReadOnlySpan<char> actual, ReadOnlySpan<char> requested)
  19. {
  20. if (actual.Length > requested.Length)
  21. {
  22. return false;
  23. }
  24. int num = 0;
  25. for (int i = 0; i < actual.Length; i++)
  26. {
  27. //char c = (char)(*(ushort*)requested.get_Item(num++));
  28. char c = requested[num++];//(char)(*(ushort*)requested.get_Item(num++));
  29. //if (char.ToLower((char)(*(ushort*)actual.get_Item(i))) != char.ToLower(c))
  30. if(char.ToLower(actual[i])!=char.ToLower(c))
  31. {
  32. if (c != '-' && c != '_')
  33. {
  34. return false;
  35. }
  36. i--;
  37. }
  38. }
  39. return num == actual.Length;
  40. }
  41. }
  42. }