using System;
using System.Text.RegularExpressions;
namespace Chernobyl.Utility
{
///
/// This class defines extension methods for enumerations.
///
public static class EnumExtensions
{
///
/// This extension method takes an item in an enumeration and turns it into
/// a string with spaces inserted between words that are capitalized.
/// i.e. the enum item "WhatTheHELL" becomes "What The HELL".
///
/// References: this method was taken and modified from
/// http://stackoverflow.com/questions/13599/convert-enums-to-human-readable-value-c
///
/// An enum item that is formatted using PascalCase.
/// The string formatted from .
public static string Wordify(this Enum theEnumItem)
{
return EnumWordifierRegex.Replace(theEnumItem.ToString(), " ${x}");
}
///
/// The used in the
/// method to turn an enum into a word with spaces.
///
static readonly Regex EnumWordifierRegex = new Regex("(?<=[a-z])(?[A-Z])|(?<=.)(?[A-Z])(?=[a-z])", RegexOptions.Compiled);
}
}