CommonFunction.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. using System.Runtime.Serialization;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using static Venus_Core.NiceRobotAction;
  10. namespace Venus_MainPages.Unity
  11. {
  12. public static class CommonFunction
  13. {
  14. //internal T
  15. public static T GetValue<T>(Dictionary<string, object> RtDataValues, string str)
  16. {
  17. if (RtDataValues==null)
  18. {
  19. return default(T);
  20. }
  21. if (RtDataValues.Keys.Contains(str))
  22. {
  23. try
  24. {
  25. if(RtDataValues[str]!=null)
  26. return (T)Convert.ChangeType(RtDataValues[str], typeof(T));
  27. else
  28. {
  29. return default(T);
  30. }
  31. }
  32. catch
  33. {
  34. return default(T);
  35. }
  36. }
  37. else
  38. {
  39. return default(T);
  40. }
  41. }
  42. public static IEnumerable<string> GetFilesNames(string path)
  43. {
  44. if (Directory.Exists(path))
  45. {
  46. return Directory.GetFiles(path, "*.rcp")?
  47. .Select(Path.GetFileNameWithoutExtension);
  48. }
  49. else
  50. {
  51. return new List<string>();
  52. }
  53. }
  54. public static T ToEnum<T>(this string value,out bool isParseOK) where T : struct
  55. {
  56. T result;
  57. if (Enum.TryParse<T>(value, true, out result))
  58. {
  59. isParseOK = true;
  60. return result;
  61. }
  62. else
  63. {
  64. isParseOK = false;
  65. return default(T);
  66. }
  67. }
  68. }
  69. }