/// <summary> /// Gets a value from the environment, using the provided <paramref name="key"/>. If the value could not be found, then /// a provided default value is returned. /// </summary> /// <param name="environment">The <see cref="INancyEnvironment"/> instance.</param> /// <param name="key">The key to retrieve the value for.</param> /// <param name="defaultValue">The value to return if no stored value could be found.</param> /// <typeparam name="T">The <see cref="Type"/> of the value to retreive from the environment.</typeparam> /// <returns>The stored value.</returns> public static T GetValueWithDefault <T>(this INancyEnvironment environment, string key, T defaultValue) { T value; return(environment.TryGetValue(key, out value) ? value : defaultValue); }
/// <summary> /// Gets a value from the environment, using the full name of the type defined by <typeparamref name="T"/> as the key. If /// the value could not be found, then a provided default value is returned. /// </summary> /// <param name="environment">The <see cref="INancyEnvironment"/> instance.</param> /// <param name="defaultValue">The value to return if no stored value could be found.</param> /// <typeparam name="T">The <see cref="Type"/> of the value to retreive from the environment.</typeparam> /// <returns>The stored value.</returns> public static T GetValueWithDefault <T>(this INancyEnvironment environment, T defaultValue) { T value; return(environment.TryGetValue(typeof(T).FullName, out value) ? value : defaultValue); }