@@ -45,7 +45,7 @@ public static Uri GetBaseServerUri(String serviceName) {
4545 /// <param name="keyName">Name of the key.</param>
4646 /// <returns></returns>
4747 public static String GetConnectionString ( String keyName ) {
48- return ConfigurationReader . GetValueFromSection < String > ( "ConnectionStrings" , keyName ) ;
48+ return ConfigurationReader . GetValueFromSection ( "ConnectionStrings" , keyName ) ;
4949 }
5050
5151 /// <summary>
@@ -54,7 +54,7 @@ public static String GetConnectionString(String keyName) {
5454 /// <param name="keyName">Name of the key.</param>
5555 /// <returns></returns>
5656 public static String GetValue ( String keyName ) {
57- return ConfigurationReader . GetValueFromSection < String > ( "AppSettings" , keyName ) ;
57+ return ConfigurationReader . GetValueFromSection ( "AppSettings" , keyName ) ;
5858 }
5959
6060 /// <summary>
@@ -65,12 +65,12 @@ public static String GetValue(String keyName) {
6565 /// <returns></returns>
6666 public static String GetValue ( String sectionName ,
6767 String keyName ) {
68- return ConfigurationReader . GetValueFromSection < String > ( sectionName , keyName ) ;
68+ return ConfigurationReader . GetValueFromSection ( sectionName , keyName ) ;
6969 }
7070
71- public static T GetValue < T > ( String sectionName ,
72- String keyName ) {
73- return ConfigurationReader . GetValueFromSection < T > ( sectionName , keyName ) ;
71+ public static T GetValueFromSection < T > ( String sectionName ,
72+ String keyName ) {
73+ return ConfigurationReader . GetTypedValueFromSection < T > ( sectionName , keyName ) ;
7474 }
7575
7676 /// <summary>
@@ -83,7 +83,27 @@ public static void Initialise(IConfigurationRoot configurationRoot) {
8383 ConfigurationReader . IsInitialised = true ;
8484 }
8585
86- private static T GetValueFromSection < T > ( String sectionName ,
86+ private static String GetValueFromSection ( String sectionName , String keyName )
87+ {
88+ if ( ! ConfigurationReader . IsInitialised )
89+ {
90+ throw new InvalidOperationException ( "Configuration Reader has not been initialised" ) ;
91+ }
92+ IConfigurationSection section = ConfigurationReader . ConfigurationRoot . GetSection ( sectionName ) ;
93+ if ( section == null )
94+ {
95+ throw new Exception ( $ "Section [{ sectionName } ] not found.") ;
96+ }
97+
98+ if ( section [ keyName ] == null )
99+ {
100+ throw new Exception ( $ "No configuration value was found for key [{ sectionName } :{ keyName } ]") ;
101+ }
102+
103+ return section [ keyName ] ;
104+ }
105+
106+ private static T GetTypedValueFromSection < T > ( String sectionName ,
87107 String keyName ) {
88108 if ( ! ConfigurationReader . IsInitialised ) {
89109 throw new InvalidOperationException ( "Configuration Reader has not been initialised" ) ;
0 commit comments