예제 #1
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);
        }
예제 #2
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);
        }
예제 #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>
        ///     获得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);
        }
예제 #5
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);
        }