终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

101 řádky
3.1 KiB

  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace BPASmartClient.Helper
  9. {
  10. public static class ExpandMethod
  11. {
  12. /// <summary>
  13. /// 获取布尔数组指定值得索引
  14. /// </summary>
  15. /// <param name="obj">要获取索引的数组</param>
  16. /// <param name="value">要获取索引的值</param>
  17. /// <returns></returns>
  18. public static int GetIndex(this bool[] obj, bool value)
  19. {
  20. if (obj == null) return -1;
  21. return Array.FindIndex(obj, p => p == value);
  22. }
  23. /// <summary>
  24. /// 获取字符串数组指定值得索引
  25. /// </summary>
  26. /// <param name="obj">要获取索引的数组</param>
  27. /// <param name="value">要获取索引的值</param>
  28. /// <returns></returns>
  29. public static int GetIndex(this string[] obj, string value)
  30. {
  31. if (obj == null || value == null) return -1;
  32. return Array.FindIndex(obj, p => p == value && p.Length > 0);
  33. }
  34. /// <summary>
  35. /// 委托回调
  36. /// </summary>
  37. /// <param name="action">要执行的委托</param>
  38. /// <param name="callback">委托回调</param>
  39. public static void Invoke(this Action action, Action callback)
  40. {
  41. if (action != null)
  42. {
  43. action();
  44. if (callback != null) callback();
  45. }
  46. }
  47. /// <summary>
  48. /// 委托回调
  49. /// </summary>
  50. /// <param name="action">要执行的委托</param>
  51. /// <param name="par">要执行的委托的参数</param>
  52. /// <param name="callback">委托回调</param>
  53. public static void Invoke(this Action<object> action, object par, Action callback)
  54. {
  55. if (action != null)
  56. {
  57. action(par);
  58. if (callback != null) callback();
  59. }
  60. }
  61. ///// <summary>
  62. ///// 保存数据
  63. ///// </summary>
  64. //public static void Save<T>(this T ot)
  65. //{
  66. // string outjson = JsonConvert.SerializeObject(ot);
  67. // var str = ot.GetType().GenericTypeArguments;
  68. // if (str != null && str.Length > 0)
  69. // {
  70. // File.WriteAllText(LocaPath.GetInstance.Getpath(str[0].Name), outjson);
  71. // }
  72. //}
  73. ///// <summary>
  74. ///// 获取保存的数据
  75. ///// </summary>
  76. //public static void Read(this object ot)
  77. //{
  78. // var str = ot.GetType().GenericTypeArguments;
  79. // if (str != null && str.Length > 0)
  80. // {
  81. // string pa = LocaPath.GetInstance.Getpath(str[0].Name);
  82. // if (File.Exists(pa))
  83. // {
  84. // string JsonString = File.ReadAllText(pa);
  85. // var result = JsonConvert.DeserializeObject<object>(JsonString);
  86. // if (result != null) { Json<object>.Data = result; }
  87. // }
  88. // }
  89. //}
  90. }
  91. }