终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

116 rivejä
3.6 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. action?.Invoke();
  42. callback?.Invoke();
  43. //if (action != null)
  44. //{
  45. // action();
  46. // if (callback != null) callback();
  47. //}
  48. }
  49. /// <summary>
  50. /// 委托回调
  51. /// </summary>
  52. /// <param name="action">要执行的委托</param>
  53. /// <param name="par">要执行的委托的参数</param>
  54. /// <param name="callback">委托回调</param>
  55. public static void Invoke(this Action<object> action, object par, Action callback)
  56. {
  57. action?.Invoke(par);
  58. callback?.Invoke();
  59. //if (action != null)
  60. //{
  61. // action(par);
  62. // if (callback != null) callback();
  63. //}
  64. }
  65. public static void Invokes(this Action<object[]> action, object[] par, Action callback)
  66. {
  67. action?.Invoke(par);
  68. callback?.Invoke();
  69. //if (action != null)
  70. //{
  71. // action(par);
  72. // if (callback != null) callback();
  73. //}
  74. }
  75. ///// <summary>
  76. ///// 保存数据
  77. ///// </summary>
  78. //public static void Save<T>(this T ot)
  79. //{
  80. // string outjson = JsonConvert.SerializeObject(ot);
  81. // var str = ot.GetType().GenericTypeArguments;
  82. // if (str != null && str.Length > 0)
  83. // {
  84. // File.WriteAllText(LocaPath.GetInstance.Getpath(str[0].Name), outjson);
  85. // }
  86. //}
  87. ///// <summary>
  88. ///// 获取保存的数据
  89. ///// </summary>
  90. //public static void Read(this object ot)
  91. //{
  92. // var str = ot.GetType().GenericTypeArguments;
  93. // if (str != null && str.Length > 0)
  94. // {
  95. // string pa = LocaPath.GetInstance.Getpath(str[0].Name);
  96. // if (File.Exists(pa))
  97. // {
  98. // string JsonString = File.ReadAllText(pa);
  99. // var result = JsonConvert.DeserializeObject<object>(JsonString);
  100. // if (result != null) { Json<object>.Data = result; }
  101. // }
  102. // }
  103. //}
  104. }
  105. }