Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
|
- using BPASmartClient.Model;
- using Model;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.MilkWithTea
- {
- public class GLobal
- {
- //路径
- public static string recipePath = string.Empty;
- public static string posionPath = string.Empty;
-
- public static bool makeEnable = false;
-
- public static ObservableCollection<LocalTeaWithMilkConfig> MaterialRecipes { get; set; } = new ObservableCollection<LocalTeaWithMilkConfig>();
- /// <summary>
- /// 设备信息列表
- /// </summary>
- public static ObservableCollection<DeviceConfigModelJson> deviceConfig { get; set; } = new ObservableCollection<DeviceConfigModelJson>();
-
-
- /// <summary>
- /// 获取Json文件内容,转换成ObservableCollection
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="path"></param>
- /// <returns></returns>
- public static ObservableCollection<T> GetJsonToT<T>(string path)
- {
- if (!File.Exists(path))
- {
- //创建该文件
- File.Create(path);
- return default;
- }
- else
- {
- using (StreamReader recipeReader = new StreamReader(path))//读取json文件
- {
- string datacache = "";
- string line;
- while ((line = recipeReader.ReadLine()) != null) //循环将每一行数据拼接为一个完整的字符串
- {
- datacache = datacache + line;
- }
-
- var res = JsonConvert.DeserializeObject<ObservableCollection<T>>(datacache); //将string转换为class类,从而达到json文件转换的目的
- if (res != null)
- return res;
- else return new ObservableCollection<T> { };
- }
- }
- }
- }
- }
|