using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.Helper { public static class ExpandMethod { /// /// 获取布尔数组指定值得索引 /// /// 要获取索引的数组 /// 要获取索引的值 /// public static int GetIndex(this bool[] obj, bool value) { if (obj == null) return -1; return Array.FindIndex(obj, p => p == value); } /// /// 获取字符串数组指定值得索引 /// /// 要获取索引的数组 /// 要获取索引的值 /// public static int GetIndex(this string[] obj, string value) { if (obj == null || value == null) return -1; return Array.FindIndex(obj, p => p == value && p.Length > 0); } /// /// 委托回调 /// /// 要执行的委托 /// 委托回调 public static void Invoke(this Action action, Action callback) { if (action != null) { action(); if (callback != null) callback(); } } /// /// 委托回调 /// /// 要执行的委托 /// 要执行的委托的参数 /// 委托回调 public static void Invoke(this Action action, object par, Action callback) { if (action != null) { action(par); if (callback != null) callback(); } } ///// ///// 保存数据 ///// //public static void Save(this T ot) //{ // string outjson = JsonConvert.SerializeObject(ot); // var str = ot.GetType().GenericTypeArguments; // if (str != null && str.Length > 0) // { // File.WriteAllText(LocaPath.GetInstance.Getpath(str[0].Name), outjson); // } //} ///// ///// 获取保存的数据 ///// //public static void Read(this object ot) //{ // var str = ot.GetType().GenericTypeArguments; // if (str != null && str.Length > 0) // { // string pa = LocaPath.GetInstance.Getpath(str[0].Name); // if (File.Exists(pa)) // { // string JsonString = File.ReadAllText(pa); // var result = JsonConvert.DeserializeObject(JsonString); // if (result != null) { Json.Data = result; } // } // } //} } }