|
//-----------------------------------------------------------------------
// <copyright file="Extensions.cs" company="None">
// No copyright restrictions apply.
// </copyright>
//-----------------------------------------------------------------------
namespace RestPad
{
using System;
using System.ComponentModel;
using System.Net;
/// <summary>
/// The module which holds all extension methods used by RestPad.
/// </summary>
public static class Extensions
{
/// <summary>
/// Gets the value of the specified header, or returns the defaultValue if no header exists.
/// </summary>
/// <typeparam name="T">The type of value to retrieve.</typeparam>
/// <param name="headers">The headers collection.</param>
/// <param name="key">The header key.</param>
/// <param name="defaultValue">The default value to be returned if the header does not exist.</param>
/// <returns>The value of the header or defaultValue if the header cannot be found.</returns>
public static T GetValue<T>(this WebHeaderCollection headers, string key, T defaultValue)
{
string header = headers[key];
if (string.IsNullOrEmpty(header))
{
return defaultValue;
}
return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(header);
}
/// <summary>
/// Gets a value indicating whether or not the exception is dangerous.
/// </summary>
/// <param name="ex">The exception to evaluate.</param>
/// <returns>A value indicating whether or not the exception is dangerous.</returns>
public static bool IsDangerous(this Exception ex)
{
return ex is OutOfMemoryException;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.