CommonFunction.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. namespace Venus_MainPages.Unity
  10. {
  11. public static class CommonFunction
  12. {
  13. //internal T
  14. public static T GetValue<T>(Dictionary<string, object> RtDataValues, string str)
  15. {
  16. if (RtDataValues.Keys.Contains(str))
  17. {
  18. try
  19. {
  20. if(RtDataValues[str]!=null)
  21. return (T)Convert.ChangeType(RtDataValues[str], typeof(T));
  22. else
  23. {
  24. return default(T);
  25. }
  26. }
  27. catch
  28. {
  29. return default(T);
  30. }
  31. }
  32. else
  33. {
  34. return default(T);
  35. }
  36. }
  37. public static IEnumerable<string> GetFilesNames(string path)
  38. {
  39. if (Directory.Exists(path))
  40. {
  41. return Directory.GetFiles(path, "*.rcp")?
  42. .Select(Path.GetFileNameWithoutExtension);
  43. }
  44. else
  45. {
  46. return new List<string>();
  47. }
  48. }
  49. }
  50. }