Пример #1
0
        /// <summary>
        ///     获得Double数据
        /// </summary>
        /// <returns></returns>
        public string GetString()
        {
            if (type != KeyValueType.String)
            {
                throw new Exception(string.Format("global {0} not string type", Key));
            }

            if (isInitString)
            {
                return(stringValue);
            }

            if (!KeyValueConfigManger.ContainsKey(Key))
            {
                Logs.Warn(string.Format("Global item {0} not default.", Key));
                stringValue = defaultStringValue;
            }
            else
            {
                stringValue = KeyValueConfigManger.GetValue(Key);
            }

            isInitString = true;

            return(stringValue);
        }
Пример #2
0
        /// <summary>
        ///     获得Double数据
        /// </summary>
        /// <returns></returns>
        public double GetDouble()
        {
            if (type != KeyValueType.Double)
            {
                throw new Exception(string.Format("global {0} not double type", Key));
            }

            if (isInitDouble)
            {
                return(doubleValue);
            }

            string value = KeyValueConfigManger.GetValue(Key);

            if (string.IsNullOrEmpty(value))
            {
                Logs.Warn(string.Format("Global item {0} not default.", Key));
                doubleValue = defaultDoubleValue;
            }
            else if (!double.TryParse(value, out doubleValue))
            {
                Logs.Error(string.Format("Global item {0}:{1} parse to double fail.", Key, value));
                doubleValue = defaultDoubleValue;
            }
            isInitDouble = true;

            return(intValue);
        }
Пример #3
0
        /// <summary>
        ///     获得Int数据
        /// </summary>
        /// <returns></returns>
        public int GetInt()
        {
            if (type != KeyValueType.Int)
            {
                throw new Exception(string.Format("global {0} not int type", Key));
            }

            if (isInitInt)
            {
                return(intValue);
            }

            string value = KeyValueConfigManger.GetValue(Key);

            if (string.IsNullOrEmpty(value))
            {
                Logs.Warn(string.Format("Global item {0} not default.", Key));
                intValue = defaultIntValue;
            }
            else if (!int.TryParse(value, out intValue))
            {
                Logs.Error(string.Format("Global item {0}:{1} parse to int fail.", Key, value));
                intValue = defaultIntValue;
            }
            isInitInt = true;

            return(intValue);
        }
Пример #4
0
 /// <summary>
 ///     创建一个int类型的数据
 /// </summary>
 /// <param name="key"></param>
 /// <param name="defaultValue"></param>
 public KeyValueItem(string key, int defaultValue)
 {
     KeyValueConfigManger.AddUpdateItem(this);
     defaultIntValue = defaultValue;
     Key             = key;
     type            = KeyValueType.Int;
 }
Пример #5
0
        /// <summary>
        ///     创建一个int[] 类型的数据
        /// </summary>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        public KeyValueItem(string key, string[] defaultValue)
        {
            KeyValueConfigManger.AddUpdateItem(this);

            defaultStringArray = defaultValue;
            Key  = key;
            type = KeyValueType.StringArray;
        }
Пример #6
0
        /// <summary>
        ///     创建一个Double[] 类型的数据
        /// </summary>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        public KeyValueItem(string key, double[] defaultValue)
        {
            KeyValueConfigManger.AddUpdateItem(this);

            defaultDoubleArray = defaultValue;
            Key  = key;
            type = KeyValueType.DoubleArray;
        }
Пример #7
0
        /// <summary>
        ///     获得Double数据
        /// </summary>
        /// <returns></returns>
        public double[] GetDoubleArray()
        {
            if (type != KeyValueType.IntArray)
            {
                throw new Exception(string.Format("global {0} not dboule[] type", Key));
            }

            if (isInitDoubleArray)
            {
                return(doubleArray);
            }

            string value = KeyValueConfigManger.GetValue(Key);

            if (string.IsNullOrEmpty(value))
            {
                Logs.Warn(string.Format("Global item {0} not default.", Key));
                doubleArray = defaultDoubleArray;
            }
            else
            {
                List <double> arr = new List <double>();
                foreach (var str in value.Split(',', ';'))
                {
                    if (string.IsNullOrEmpty(str))
                    {
                        continue;
                    }

                    double i;
                    if (double.TryParse(str, out i))
                    {
                        arr.Add(i);
                    }
                    else
                    {
                        Logs.Error(string.Format("Global item {0}:{1}-{2} parse to dboule fail.", Key, value, str));
                    }
                }
                doubleArray = arr.ToArray();
            }

            isInitDoubleArray = true;

            return(doubleArray);
        }
Пример #8
0
        /// <summary>
        ///     获得Int数据
        /// </summary>
        /// <returns></returns>
        public string[] GetStringArray()
        {
            if (type != KeyValueType.StringArray)
            {
                throw new Exception(string.Format("global {0} not string[] type", Key));
            }

            if (isInitStringArray)
            {
                return(stringArray);
            }

            string value = KeyValueConfigManger.GetValue(Key);

            if (string.IsNullOrEmpty(value))
            {
                Logs.Warn(string.Format("Global item {0} not default.", Key));
                stringArray = defaultStringArray;
            }
            else
            {
                List <string> arr = new List <string>();
                foreach (var str in value.Split(',', ';'))
                {
                    if (string.IsNullOrEmpty(str))
                    {
                        continue;
                    }

                    arr.Add(str);
                }
                stringArray = arr.ToArray();
            }

            isInitStringArray = true;

            return(stringArray);
        }