Esempio n. 1
0
        /// <summary>
        /// 通过键读取配置文件信息
        /// </summary>
        /// <param name="PathMap">自定义属性信息</param>
        /// <returns>值</returns>
        private static string GetConfigValue(PathMapAttribute PathMap)
        {
            string       path = GetXmlPath(PathMap.Key, PathMap.XmlPath);
            XmlNode      node = null;
            XmlAttribute attr = null;

            try
            {
                node = doc.SelectSingleNode(path);
                if (node != null)
                {
                    attr = node.Attributes["value"];
                    if (attr == null)
                    {
                        throw new Exception("服务器配置文件设置异常,节点" + PathMap.Key + "没有相应的value属性,请检查!");
                    }
                    return(GetRealValue(attr.Value, PathMap.IsDecrypt));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return("");
        }
Esempio n. 2
0
 /// <summary>
 /// 初始化配置信息
 /// </summary>
 public static void InitConfig <T>() where T : new()
 {
     try
     {
         doc = new XmlDocument();
         if (!File.Exists(ConfigPath))
         {
             return;
         }
         //读取服务器配置文件信息
         doc.Load(ConfigPath);
         Type             type    = typeof(T);
         PropertyInfo[]   Props   = type.GetProperties(flags);
         PathMapAttribute PathMap = null;
         foreach (var prop in Props)
         {
             PathMap = GetMyAttribute <PathMapAttribute>(prop, false);
             if (PathMap != null)
             {
                 prop.SetValue(null, Convert.ChangeType(GetConfigValue(PathMap), prop.PropertyType), null);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }