// -----------------------------------------------------------------------
//
// TODO: Update copyright text.
//
// -----------------------------------------------------------------------
namespace ImageProcessor.Helpers.Extensions
{
#region Using
using System;
using System.ComponentModel;
using System.Diagnostics.Contracts;
#endregion
///
/// Encapsulates a series of time saving extension methods to Enums.
///
public static class EnumExtensions
{
#region Methods
///
/// Extends the Enum type to return the description attribute for the given type.
/// Useful for when the type to match in the data source contains spaces.
///
/// The given Enum that this method extends.
/// A string containing the Enum's description attribute.
public static string ToDescription(this Enum expression)
{
Contract.Requires(expression != null);
DescriptionAttribute[] descriptionAttribute =
(DescriptionAttribute[])
expression.GetType().GetField(expression.ToString())
.GetCustomAttributes(typeof(DescriptionAttribute), false);
return descriptionAttribute.Length > 0 ? descriptionAttribute[0].Description : expression.ToString();
}
#endregion
}
}