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ů.
|
- 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>
- /// 获取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> { };
- }
- }
- }
- }
- }
|