终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

110 wiersze
3.4 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. public static void Invokes(this Action<object[]> action, object[] par, Action callback)
  62. {
  63. if (action != null)
  64. {
  65. action(par);
  66. if (callback != null) callback();
  67. }
  68. }
  69. ///// <summary>
  70. ///// 保存数据
  71. ///// </summary>
  72. //public static void Save<T>(this T ot)
  73. //{
  74. // string outjson = JsonConvert.SerializeObject(ot);
  75. // var str = ot.GetType().GenericTypeArguments;
  76. // if (str != null && str.Length > 0)
  77. // {
  78. // File.WriteAllText(LocaPath.GetInstance.Getpath(str[0].Name), outjson);
  79. // }
  80. //}
  81. ///// <summary>
  82. ///// 获取保存的数据
  83. ///// </summary>
  84. //public static void Read(this object ot)
  85. //{
  86. // var str = ot.GetType().GenericTypeArguments;
  87. // if (str != null && str.Length > 0)
  88. // {
  89. // string pa = LocaPath.GetInstance.Getpath(str[0].Name);
  90. // if (File.Exists(pa))
  91. // {
  92. // string JsonString = File.ReadAllText(pa);
  93. // var result = JsonConvert.DeserializeObject<object>(JsonString);
  94. // if (result != null) { Json<object>.Data = result; }
  95. // }
  96. // }
  97. //}
  98. }
  99. }