Documentation Coverage Report
Current view: top level - Cqrs/Configuration - ConfigurationManager.cs Hit Total Coverage
Version: 2.2 Artefacts: 4 4 100.0 %
Date: 2018-08-07 15:04:50

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="Chinchilla Software Limited">
       4             : // //   Copyright Chinchilla Software Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : 
      11             : namespace Cqrs.Configuration
      12             : {
      13             :         /// <summary>
      14             :         /// Provides access to configuration settings from the app settings of an app.config or web.config... i.e. <see cref="System.Configuration.ConfigurationManager.AppSettings"/>
      15             :         /// </summary>
      16             :         public class ConfigurationManager : IConfigurationManager
      17           1 :         {
      18             :                 #region Implementation of IConfigurationManager
      19             : 
      20             :                 /// <summary>
      21             :                 /// Read the setting named <paramref name="key"/>.
      22             :                 /// </summary>
      23             :                 /// <param name="key">The key (or name) of the setting to read.</param>
      24           1 :                 public virtual string GetSetting(string key)
      25             :                 {
      26             :                         return System.Configuration.ConfigurationManager.AppSettings[key];
      27             :                 }
      28             : 
      29             :                 /// <summary>
      30             :                 /// Read the setting named <paramref name="key"/>.
      31             :                 /// </summary>
      32             :                 /// <param name="key">The key (or name) of the setting to read.</param>
      33             :                 /// <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
      34             :                 /// <returns>true if the an element with the specified key exists; otherwise, false.</returns>
      35           1 :                 public virtual bool TryGetSetting(string key, out string value)
      36             :                 {
      37             :                         try
      38             :                         {
      39             :                                 value = GetSetting(key);
      40             :                                 return true;
      41             :                         }
      42             :                         catch (Exception)
      43             :                         {
      44             :                                 value = null;
      45             :                                 return false;
      46             :                         }
      47             :                 }
      48             : 
      49             :                 /// <summary>
      50             :                 /// Read the setting named <paramref name="key"/>.
      51             :                 /// </summary>
      52             :                 /// <param name="key">The key (or name) of the setting to read.</param>
      53             :                 /// <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
      54             :                 /// <returns>true if the an element with the specified key exists; otherwise, false.</returns>
      55           1 :                 public virtual bool TryGetSetting(string key, out bool value)
      56             :                 {
      57             :                         string rawValue;
      58             :                         if (TryGetSetting(key, out rawValue))
      59             :                         {
      60             :                                 if (bool.TryParse(rawValue, out value))
      61             :                                 {
      62             :                                         return true;
      63             :                                 }
      64             :                         }
      65             :                         value = false;
      66             :                         return false;
      67             :                 }
      68             : 
      69             :                 #endregion
      70             :         }
      71             : }

Generated by: LCOV version 1.12