王 垚
2022-09-05 226dd2b152c0fb06b3f8108ac7740216a8a453c6
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
 
namespace ZD.Share.Common
{
    public class Util
    {
        public static string GetObjectType(object obj)
        {
            var isType = false;
            isType = obj.GetType() == typeof(string);
            if (isType)
            {
                return "string";
            }
 
            isType = obj.GetType() == typeof(double);
            if (isType)
            {
                return "double";
            }
 
            isType = obj.GetType() == typeof(long);
            if (isType)
            {
                return "long";
            }
 
            isType = obj.GetType() == typeof(DateTime);
            if (isType)
            {
                return "date";
            }
 
            isType = obj.GetType() == typeof(int);
            if (isType)
            {
                return "int";
            }
 
            isType = obj.GetType() == typeof(decimal);
            if (isType)
            {
                return "decimal";
            }
 
            return "string";
        }
 
        public static JObject JsonVerify(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                throw new Exception("参数不能为空");
            }
            try
            {
                return JObject.Parse(json.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", ""));
            }
            catch (Exception)
            {
                throw;
            }
        }
 
        //public static T DeepCopy<T>(T obj)
        //{
        //    object retval;
        //    using (MemoryStream ms = new MemoryStream())
        //    {
        //        XmlSerializer xml = new XmlSerializer(typeof(T));
        //        xml.Serialize(ms, obj);
        //        ms.Seek(0, SeekOrigin.Begin);
        //        retval = xml.Deserialize(ms);
        //        ms.Close();
        //    }
        //    return (T)retval;
        //}
 
        public static String GetConfigKey(String configPath, String key)
        {
            Configuration ConfigurationInstance = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap()
            {
                ExeConfigFilename = configPath
            }, ConfigurationUserLevel.None);
 
 
            if (ConfigurationInstance.AppSettings.Settings[key] != null)
                return ConfigurationInstance.AppSettings.Settings[key].Value;
            else
 
                return string.Empty;
        }
 
        public static bool SetConfigKey(String configPath, String key, String vls)
        {
            try
            {
                Configuration ConfigurationInstance = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap()
                {
                    ExeConfigFilename = configPath
                }, ConfigurationUserLevel.None);
 
                if (ConfigurationInstance.AppSettings.Settings[key] != null)
                    ConfigurationInstance.AppSettings.Settings[key].Value = vls;
                else
                    ConfigurationInstance.AppSettings.Settings.Add(key, vls);
                ConfigurationInstance.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}