Exemplo n.º 1
0
        static Dictionary <SysCategory, string> GetLogWebApplicationsNameFromFile()
        {
            List <KVEdm> kVEdms = Log2NetConfig.GetSectionVal("userSystemNames");

            if (kVEdms.Count > 0)
            {
                Dictionary <SysCategory, string> dic = kVEdms.ToDictionary(k => StringEnum.GetEnumValue <SysCategory>(k.Key), v => v.Value);
                return(dic);
            }
            else
            {
                var enumDic = StringEnum.GetDicFromEnumType(new SysCategory());
                return(enumDic.ToDictionary(k => (SysCategory)k.Value, v => v.Key));
            }
        }
Exemplo n.º 2
0
        //从文件中获取配置值
        static T GetCfgValueFromFile <T>(string keyInFie, T defaultVal)
        {
            T   result  = defaultVal;
            var curVal  = Log2NetConfig.GetConfigVal(keyInFie);
            var curType = typeof(T);

            if (curType.IsEnum)
            {
                result = StringEnum.GetEnumValue <T>(curVal);
                return(result);
            }
            if (curType.Name == "Boolean")
            {
                curVal = curVal == "1" || curVal.Equals("true", StringComparison.OrdinalIgnoreCase) ? "true" : "false";
            }
            result = (T)Convert.ChangeType(curVal, typeof(T));
            return(result);
        }