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 WebAPI.Utility 
 | 
{ 
 | 
    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; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
} 
 |