CommonFunction.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.Keys.Contains(str))
  18. {
  19. try
  20. {
  21. if(RtDataValues[str]!=null)
  22. return (T)Convert.ChangeType(RtDataValues[str], typeof(T));
  23. else
  24. {
  25. return default(T);
  26. }
  27. }
  28. catch
  29. {
  30. return default(T);
  31. }
  32. }
  33. else
  34. {
  35. return default(T);
  36. }
  37. }
  38. public static IEnumerable<string> GetFilesNames(string path)
  39. {
  40. if (Directory.Exists(path))
  41. {
  42. return Directory.GetFiles(path, "*.rcp")?
  43. .Select(Path.GetFileNameWithoutExtension);
  44. }
  45. else
  46. {
  47. return new List<string>();
  48. }
  49. }
  50. public static T ToEnum<T>(this string value,out bool isParseOK) where T : struct
  51. {
  52. T result;
  53. if (Enum.TryParse<T>(value, true, out result))
  54. {
  55. isParseOK = true;
  56. return result;
  57. }
  58. else
  59. {
  60. isParseOK = false;
  61. return default(T);
  62. }
  63. }
  64. }
  65. }