ConfigAppSettings.cs 1.5 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Threading;
using System.Xml;
using System.Windows.Forms;
using log4net;

namespace OnlineStore.Common
{
    public class ConfigAppSettings
    {
        private static int seq = 1;

        public static int nextSeq()
        {
            if (seq.Equals(Int32.MaxValue))
            {
                LogUtil.info("seq当前值:" + seq + ",重置seq=0");
                seq = 0;
            }
            Interlocked.Increment(ref seq);
            return seq;
        }

        public static T GetValue<T>(string key, T defaultVal =default(T),string comment="")
        {
            return getVal(key, defaultVal, comment);
        }
        static T getVal<T>(string key, T defaultVal = default(T),string comment="")
        {
            ConfigHelper.Config.SetComment(key, comment);
            return ConfigHelper.Config.Get<T>(key, defaultVal);
        }
        public static int GetIntValue(string key,int defaultVal=0,string comment="")
        {
            return getVal(key, defaultVal,comment);
        }
        public static void SaveValue<T>(string key, T value, string comment = "")
        {
            ConfigHelper.Config.SetComment(key, comment);
            ConfigHelper.Config.Set(key, value);
        }
        /// <summary>
        /// 模拟
        /// </summary>
        public static bool simulationMode { get { return getVal(Setting_Init.simulationMode, true); } }
    }
}