Ejemplo n.º 1
0
        public static MailSection GetConfig()
        {
            MailSection configSection = (MailSection)ConfigurationManager.GetSection("MailSection");

            if (configSection == null)
            {
                throw new ConfigurationErrorsException("Section [MailSection] is not found.");
            }
            return(configSection);
        }
Ejemplo n.º 2
0
        public static MailSection GetConfig(string configPath)
        {
            var fileMap = new ExeConfigurationFileMap()
            {
                ExeConfigFilename = configPath
            };
            var         config        = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            MailSection configSection = (MailSection)config.GetSection("MailSection");

            if (configSection == null)
            {
                throw new ConfigurationErrorsException("Section [MailSection] is not found.");
            }
            return(configSection);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取指定的配置对象
        /// </summary>
        /// <param name="keyName">配置名称</param>
        /// <returns></returns>
        public static PrintKeyValue GetTheKeyValueCollection(string keyName)
        {
            MailSection configSection = (MailSection)ConfigurationManager.GetSection("MailSection");

            if (configSection == null)
            {
                throw new ConfigurationErrorsException("Section [MailSection] is not found.");
            }
            foreach (PrintKeyValue item in configSection.KeyValues)
            {
                if (item.Name == keyName)
                {
                    return(item);
                }
            }
            return(null);
        }