Permalink
Browse files

adding TryGet<T> to configuration section

  • Loading branch information...
1 parent 48b63a1 commit 0bb959cb2a9ec748dba52310313bc60093809617 Ian Davis committed Jun 17, 2011
Binary file not shown.
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
+ <metadata>
+ <id>Innovatian.Configuration</id>
+ <version>1.0</version>
+ <title />
+ <authors>Ian Davis</authors>
+ <owners />
+ <licenseUrl>https://raw.github.com/innovatian/innovatian.configuration/master/LICENSE.txt</licenseUrl>
+ <projectUrl>https://github.com/innovatian/innovatian.configuration</projectUrl>
+ <requireLicenseAcceptance>true</requireLicenseAcceptance>
+ <description>Configuration library supporting INI, XML, Isolated Storage, Registry, command line, .NET config files as storage mechanisms.
+
+Values are returned strongly typed and advanced type conversions are applied automatically.
+
+Supports merging of heterogeneous sources into a single composite settings store with cross section value expansion capabilities.</description>
+ <summary>Configuration library supporting INI, XML, Isolated Storage, Registry, command line, .NET config files as storage mechanisms.</summary>
+ </metadata>
+ <files>
+ <file src="lib\Innovatian.Configuration.dll" target="lib\Innovatian.Configuration.dll" />
+ <file src="lib\Innovatian.Configuration.pdb" target="lib\Innovatian.Configuration.pdb" />
+ <file src="lib\Innovatian.Configuration.xml" target="lib\Innovatian.Configuration.xml" />
+ </files>
+</package>
@@ -82,6 +82,39 @@ public T Get<T>( string key )
}
/// <summary>
+ /// Returns <c>true</c> if the value of the setting name <paramref name="key"/>
+ /// exists and sets the <c>T</c> instance via the out parameter. If the key
+ /// was not found, <c>false</c> is returned and the out value is set to default(T).
+ /// </summary>
+ /// <typeparam name="T">
+ /// The type needed by the user.
+ /// </typeparam>
+ /// <param name="key">
+ /// The name of the setting.
+ /// </param>
+ /// <param name="value">
+ /// The value to set if the key exists.
+ /// </param>
+ /// <returns>returns <c>true</c> if the setting exists and sets the value as a <c>T</c> instance or
+ /// <c>false</c> if the key does not exist and sets the out value to default(T).
+ /// </returns>
+ public bool TryGet<T>(string key, out T value)
+ {
+ if (string.IsNullOrEmpty(key))
+ {
+ throw new ArgumentNullException("key");
+ }
+
+ if (_settings.ContainsKey(key))
+ {
+ value = Get<T>( key );
+ return true;
+ }
+ value = default( T );
+ return false;
+ }
+
+ /// <summary>
/// Returns the value of the setting name <paramref name="key"/> as a
/// <c>T</c> instance.
/// </summary>
@@ -45,6 +45,25 @@ public interface IConfigurationSection : INotifyPropertyChanged, ICollection<Key
T Get<T>( string key );
/// <summary>
+ /// Returns <c>true</c> if the value of the setting name <paramref name="key"/>
+ /// exists and sets the <c>T</c> instance via the out parameter. If the key
+ /// was not found, <c>false</c> is returned and the out value is set to default(T).
+ /// </summary>
+ /// <typeparam name="T">
+ /// The type needed by the user.
+ /// </typeparam>
+ /// <param name="key">
+ /// The name of the setting.
+ /// </param>
+ /// <param name="value">
+ /// The value to set if the key exists.
+ /// </param>
+ /// <returns>returns <c>true</c> if the setting exists and sets the value as a <c>T</c> instance or
+ /// <c>false</c> if the key does not exist and sets the out value to default(T).
+ /// </returns>
+ bool TryGet<T>(string key, out T value);
+
+ /// <summary>
/// Returns the value of the setting name <paramref name="key"/> as a
/// <c>T</c> instance.
/// </summary>

0 comments on commit 0bb959c

Please sign in to comment.