轮胎外观检测添加思谋语义分割模型检测工具
C3204
18 小时以前 85a4bdc866f7ce0986d629820ef3e793f8b72787
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace LB_SmartVisionCommon
{
    /// <summary>
    /// T类型-JSON--Serialize和Deserialize
    /// </summary>
    /// <typeparam name="T">T类型</typeparam>
    public static class ConfigManager<T>
    {
        /// <summary>
        /// 保存配置
        /// </summary>
        /// <typeparam name="T">T类型</typeparam>
        /// <param name="config">T类型的值</param>
        /// <param name="filePath">文件存储路径以及名称</param>
        public static void SaveConfig<T>(T config, string filePath)
        {
            if (config == null)
            {
                AsyncLogHelper.Error(nameof(config));
                throw new ArgumentNullException(nameof(config));
            }
            if (filePath == null)
            {
                AsyncLogHelper.Error(nameof(filePath));
                AsyncLogHelper.Error(nameof(filePath));
            }
            var json = JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented);
            File.WriteAllText(filePath, json);
        }
        /// <summary>
        /// 加载配置文件
        /// </summary>
        /// <typeparam name="T">T类型</typeparam>
        /// <param name="filePath">文件存储路径以及名称</param>
        /// <returns>T类型的值</returns>
        public static T LoadConfig<T>(string filePath) where T : new()
        {
            if (!File.Exists(filePath))
            {
                return new T();
            }
 
            var json = File.ReadAllText(filePath);
            return JsonConvert.DeserializeObject<T>(json);
        }
    }
}