예제 #1
0
        /// <summary>
        /// Gets value of specified key.
        /// </summary>
        /// <typeparam name="T">Type of value.</typeparam>
        /// <param name="section">A string specifying the section.</param>
        /// <param name="key">A string specifying the key.</param>
        /// <param name="refresh">Whether refresh settings before gets value.</param>
        /// <returns>The property object.</returns>
        public T GetValue <T>(string section, string key, bool refresh = false)
        {
            this.CheckNullValue(section);

            this.CheckNullValue(key);

            if (refresh)
            {
                this.Refresh();
            }

            this.m_readerWriterLock.AcquireReaderLock(Timeout.Infinite);

            try
            {
                if (this.Sections.ContainsKey(section))
                {
                    try
                    {
                        return(XmlConverter.ToObject <T>(this.Sections[section][key]));
                    }
                    catch (Exception e)
                    {
                        InternalLogger.Log(e);
                        throw;
                    }
                }
                else
                {
                    throw new KeyNotFoundException(string.Format(ConfigurationConstants.KeyNotFoundExceptionStringFormat, section));
                }
            }
            finally
            {
                this.m_readerWriterLock.ReleaseReaderLock();
            }
        }