<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:snippet="http://codexchange.org/schemas/snippet/1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title>CodeXchange: User Contributed Snippets</title>
    <link>http://www.codexchange.org</link>
    <description>Summary of the snippets published by a codexchange user</description>
    <language>en-us</language>
    <copyright>Copyright © CodeXchange, 2004-2006</copyright>
    <generator>CodeXchange RSS Feed Generator v1.0</generator>
    <webMaster>webmaster@codexchange.org</webMaster>
    <lastBuildDate>Thu, 15 Oct 2026 10:29:02 GMT</lastBuildDate>
    <ttl>20</ttl>
    <dc:language>en-us</dc:language>
    <dc:rights>Copyright © CodeXchange, 2004-2006</dc:rights>
    <dc:date>10/15/2026 10:29:02 AM</dc:date>
    <dc:publisher />
    <dc:creator>CodeXchange RSS Feed Generator v1.0</dc:creator>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=2514b9dd-a540-4039-9d6c-2ca0b4cc9007</guid>
      <title>Uses Reflection to create an instance of a generic type specified using the default constructor.</title>
      <link>/PreviewSnippet.aspx?SnippetID=2514b9dd-a540-4039-9d6c-2ca0b4cc9007</link>
      <description>Uses Reflection to create an instance of a generic type specified using the default constructor. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Mon, 22 Mar 2010 14:12:59 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=2514b9dd-a540-4039-9d6c-2ca0b4cc9007#comments</comments>
      <category>053f6cad-6b5e-4dd3-9c3d-f1b2979f7fcb</category>
      <dc:title>Uses Reflection to create an instance of a generic type specified using the default constructor.</dc:title>
      <dc:date>3/22/2010 2:12:59 PM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Creates an instance of the generic type specified using the default
        /// constructor.
        /// </summary>
        /// <typeparam name="T">The type to instantiate.</typeparam>
        /// <param name="type">The System.Type being instantiated.</param>
        /// <returns>An instance of the specified type.</returns>
        /// <example>
        /// typeof(MyObject).CreateInstance();
        /// </example>
        public static T CreateInstance<T>(this Type type) where T : new()
        {
            return Activator.CreateInstance<T>();
        }</pre>]]></content:encoded>
      <snippet:downloads>1</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=c971374b-978a-40af-9f2e-3bed32b1bc7a</guid>
      <title>String extension methods that encodes/decodes a string to Base64.</title>
      <link>/PreviewSnippet.aspx?SnippetID=c971374b-978a-40af-9f2e-3bed32b1bc7a</link>
      <description>String extension methods that encodes/decodes a string to Base64. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Tue, 23 Mar 2010 05:19:02 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=c971374b-978a-40af-9f2e-3bed32b1bc7a#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>String extension methods that encodes/decodes a string to Base64.</dc:title>
      <dc:date>3/23/2010 5:19:02 AM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Encodes the input value to a Base64 string using the default encoding.
        /// </summary>
        /// <param name="value">The input value.</param>
        /// <returns>The Base 64 encoded string</returns>
        public static string EncodeBase64(this string value)
        {
            return value.EncodeBase64(null);
        }
        /// <summary>
        /// Encodes the input value to a Base64 string using the supplied encoding.
        /// </summary>
        /// <param name="value">The input value.</param>
        /// <param name="encoding">The encoding.</param>
        /// <returns>The Base 64 encoded string</returns>
        public static string EncodeBase64(this string value, Encoding encoding)
        {
            encoding = (encoding ?? Encoding.UTF8);
            var bytes = encoding.GetBytes(value);
            return Convert.ToBase64String(bytes);
        }
        /// <summary>
        /// Decodes a Base 64 encoded value to a string using the default encoding.
        /// </summary>
        /// <param name="encodedValue">The Base 64 encoded value.</param>
        /// <returns>The decoded string</returns>
        public static string DecodeBase64(this string encodedValue)
        {
            return encodedValue.DecodeBase64(null);
        }
        /// <summary>
        /// Decodes a Base 64 encoded value to a string using the supplied encoding.
        /// </summary>
        /// <param name="encodedValue">The Base 64 encoded value.</param>
        /// <param name="encoding">The encoding.</param>
        /// <returns>The decoded string</returns>
        public static string DecodeBase64(this string encodedValue, Encoding encoding)
        {
            encoding = (encoding ?? Encoding.UTF8);
            var bytes = Convert.FromBase64String(encodedValue);
            return encoding.GetString(bytes);
        }</pre>]]></content:encoded>
      <snippet:downloads>2</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=577f2387-d133-4116-a116-588b1dc168ad</guid>
      <title>String Extension Methods to trim a string to a max length. Also able to add a suffix ex. "..." to string when truncating.</title>
      <link>/PreviewSnippet.aspx?SnippetID=577f2387-d133-4116-a116-588b1dc168ad</link>
      <description>String Extension Methods to trim a string to a max length. Also able to add a suffix ex. "..." to string when truncating. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Tue, 23 Mar 2010 05:11:34 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=577f2387-d133-4116-a116-588b1dc168ad#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>String Extension Methods to trim a string to a max length. Also able to add a suffix ex. "..." to string when truncating.</dc:title>
      <dc:date>3/23/2010 5:11:34 AM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Trims the text to a provided maximum length.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="maxLength">Maximum length.</param>
        /// <returns></returns>
        /// <remarks>Proposed by Rene Schulte</remarks>
        public static string TrimToMaxLength(this string value, int maxLength)
        {
            return (value == null || value.Length <= maxLength ? value : value.Substring(0, maxLength));
        }
        /// <summary>
        /// Trims the text to a provided maximum length and adds a suffix if required.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="maxLength">Maximum length.</param>
        /// <param name="suffix">The suffix.</param>
        /// <returns></returns>
        /// <remarks>Proposed by Rene Schulte</remarks>
        public static string TrimToMaxLength(this string value, int maxLength, string suffix)
        {
            return (value == null || value.Length <= maxLength ? value : string.Concat(value.Substring(0, maxLength), suffix));
        }
</pre>]]></content:encoded>
      <snippet:downloads>1</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=f2a0ee1b-4ceb-4ff1-a36e-5d767b2700fc</guid>
      <title>String Extension Method that Uses regular expressions to determine if the string matches to a given regex pattern.</title>
      <link>/PreviewSnippet.aspx?SnippetID=f2a0ee1b-4ceb-4ff1-a36e-5d767b2700fc</link>
      <description>String Extension Method that Uses regular expressions to determine if the string matches to a given regex pattern. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Tue, 23 Mar 2010 05:12:46 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=f2a0ee1b-4ceb-4ff1-a36e-5d767b2700fc#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>String Extension Method that Uses regular expressions to determine if the string matches to a given regex pattern.</dc:title>
      <dc:date>3/23/2010 5:12:46 AM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Uses regular expressions to determine if the string matches to a given regex pattern.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="regexPattern">The regular expression pattern.</param>
        /// <returns>
        /// 	<c>true</c> if the value is matching to the specified pattern; otherwise, <c>false</c>.
        /// </returns>
        /// <example>
        /// <code>
        /// var s = "12345";
        /// var isMatching = s.IsMatchingTo(@"^\d+$");
        /// </code>
        /// </example>
        public static bool IsMatchingTo(this string value, string regexPattern)
        {
            return IsMatchingTo(value, regexPattern, RegexOptions.None);
        }</pre>]]></content:encoded>
      <snippet:downloads>2</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=794820d3-0bd8-4325-89b9-631a4a36735d</guid>
      <title>string extension methods that uses regular expressions to split a string into parts.</title>
      <link>/PreviewSnippet.aspx?SnippetID=794820d3-0bd8-4325-89b9-631a4a36735d</link>
      <description>string extension methods that uses regular expressions to split a string into parts. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Tue, 23 Mar 2010 05:16:17 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=794820d3-0bd8-4325-89b9-631a4a36735d#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>string extension methods that uses regular expressions to split a string into parts.</dc:title>
      <dc:date>3/23/2010 5:16:17 AM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Uses regular expressions to split a string into parts.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="regexPattern">The regular expression pattern.</param>
        /// <returns>The splitted string array</returns>
        public static string[] Split(this string value, string regexPattern)
        {
            return value.Split(regexPattern, RegexOptions.None);
        }

        /// <summary>
        /// Uses regular expressions to split a string into parts.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="regexPattern">The regular expression pattern.</param>
        /// <param name="options">The regular expression options.</param>
        /// <returns>The splitted string array</returns>
        public static string[] Split(this string value, string regexPattern, RegexOptions options)
        {
            return Regex.Split(value, regexPattern, options);
        }</pre>]]></content:encoded>
      <snippet:downloads>2</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=24cec08d-0773-4c3e-9b58-6fcadc320cd1</guid>
      <title>Convert Color Type to Win32 Color value. Extension method.</title>
      <link>/PreviewSnippet.aspx?SnippetID=24cec08d-0773-4c3e-9b58-6fcadc320cd1</link>
      <description>Convert Color Type to Win32 Color value. Extension method. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Mon, 22 Mar 2010 14:25:20 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=24cec08d-0773-4c3e-9b58-6fcadc320cd1#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>Convert Color Type to Win32 Color value. Extension method.</dc:title>
      <dc:date>3/22/2010 2:25:20 PM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>public static int ToWin32Color(this Color color)
        {
            return ColorTranslator.ToWin32(color);
        }</pre>]]></content:encoded>
      <snippet:downloads>1</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=6f884896-ad06-4591-a289-79d0c633886e</guid>
      <title>Group of string extension methods that uses regular expressions to replace parts of a string.</title>
      <link>/PreviewSnippet.aspx?SnippetID=6f884896-ad06-4591-a289-79d0c633886e</link>
      <description>Group of string extension methods that uses regular expressions to replace parts of a string. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Tue, 23 Mar 2010 05:15:22 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=6f884896-ad06-4591-a289-79d0c633886e#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>Group of string extension methods that uses regular expressions to replace parts of a string.</dc:title>
      <dc:date>3/23/2010 5:15:22 AM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Uses regular expressions to replace parts of a string.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="regexPattern">The regular expression pattern.</param>
        /// <param name="replaceValue">The replacement value.</param>
        /// <returns>The newly created string</returns>
        /// <example>
        /// <code>
        /// var s = "12345";
        /// var replaced = s.ReplaceWith(@"\d", m => string.Concat(" -", m.Value, "- "));
        /// </code>
        /// </example>
        public static string ReplaceWith(this string value, string regexPattern, string replaceValue)
        {
            return ReplaceWith(value, regexPattern, regexPattern, RegexOptions.None);
        }
        /// <summary>
        /// Uses regular expressions to replace parts of a string.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="regexPattern">The regular expression pattern.</param>
        /// <param name="replaceValue">The replacement value.</param>
        /// <param name="options">The regular expression options.</param>
        /// <returns>The newly created string</returns>
        /// <example>
        /// <code>
        /// var s = "12345";
        /// var replaced = s.ReplaceWith(@"\d", m => string.Concat(" -", m.Value, "- "));
        /// </code>
        /// </example>
        public static string ReplaceWith(this string value, string regexPattern, string replaceValue, RegexOptions options)
        {
            return Regex.Replace(value, regexPattern, replaceValue, options);
        }
        /// <summary>
        /// Uses regular expressions to replace parts of a string.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="regexPattern">The regular expression pattern.</param>
        /// <param name="evaluator">The replacement method / lambda expression.</param>
        /// <returns>The newly created string</returns>
        /// <example>
        /// <code>
        /// var s = "12345";
        /// var replaced = s.ReplaceWith(@"\d", m => string.Concat(" -", m.Value, "- "));
        /// </code>
        /// </example>
        public static string ReplaceWith(this string value, string regexPattern, MatchEvaluator evaluator)
        {
            return ReplaceWith(value, regexPattern, RegexOptions.None, evaluator);
        }
        /// <summary>
        /// Uses regular expressions to replace parts of a string.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="regexPattern">The regular expression pattern.</param>
        /// <param name="options">The regular expression options.</param>
        /// <param name="evaluator">The replacement method / lambda expression.</param>
        /// <returns>The newly created string</returns>
        /// <example>
        /// <code>
        /// var s = "12345";
        /// var replaced = s.ReplaceWith(@"\d", m => string.Concat(" -", m.Value, "- "));
        /// </code>
        /// </example>
        public static string ReplaceWith(this string value, string regexPattern, RegexOptions options, MatchEvaluator evaluator)
        {
            return Regex.Replace(value, regexPattern, evaluator, options);
        }</pre>]]></content:encoded>
      <snippet:downloads>1</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=8fc9effa-6f75-4293-9d52-84164900df97</guid>
      <title>Convert Type Color to HTML Value. Extension Method</title>
      <link>/PreviewSnippet.aspx?SnippetID=8fc9effa-6f75-4293-9d52-84164900df97</link>
      <description>Convert Type Color to HTML Value. Extension Method [C#]</description>
      <author>John Tolar</author>
      <pubDate>Mon, 22 Mar 2010 14:23:53 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=8fc9effa-6f75-4293-9d52-84164900df97#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>Convert Type Color to HTML Value. Extension Method</dc:title>
      <dc:date>3/22/2010 2:23:53 PM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>public static string ToHtmlColor(this Color color)
        {
            return ColorTranslator.ToHtml(color);
        }</pre>]]></content:encoded>
      <snippet:downloads>1</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=26e26328-1f07-4ffe-8d51-8f8a1a6c5339</guid>
      <title>Use Reflectionto create an instance of the generic type specified using the parameters specified. Extension Method.</title>
      <link>/PreviewSnippet.aspx?SnippetID=26e26328-1f07-4ffe-8d51-8f8a1a6c5339</link>
      <description>Use Reflectionto create an instance of the generic type specified using the parameters specified. Extension Method. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Mon, 22 Mar 2010 14:15:48 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=26e26328-1f07-4ffe-8d51-8f8a1a6c5339#comments</comments>
      <category>053f6cad-6b5e-4dd3-9c3d-f1b2979f7fcb</category>
      <dc:title>Use Reflectionto create an instance of the generic type specified using the parameters specified. Extension Method.</dc:title>
      <dc:date>3/22/2010 2:15:48 PM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Creates an instance of the generic type specified using the parameters
        /// specified.
        /// </summary>
        /// <typeparam name="T">The type to  instantiate.</typeparam>
        /// <param name="type">The System.Type being instantiated.</param>
        /// <param name="parameters">The array of parameters to use when calling  the constructor.</param>
        /// <returns>An instance of the specified type.</returns>
        /// <exception cref="System.Exception" />
        /// <remarks>
        /// If there is not a constructor that matches the parameters then an <see cref="System.Exception"/> is
        /// thrown.
        /// </remarks>
        /// <example>
        /// typeof(MyObject).CreateInstance(new object[] { 1, 3.0M, "Final Parameter" });
        /// </example>
        public static T CreateInstance<T>(this Type type, object[] parameters)
        {
            parameters.ExceptionIfNullOrEmpty("The parameters array must not be null.", "parameters");
            var ctor = type.GetConstructor(parameters.Select(parameter => parameter.IsNull() ? typeof (object) : parameter.GetType()).ToArray());
            if (ctor.IsNull())
            {
                throw new ArgumentException("There are no constructors for " +
                                            type.FullName + " that match the types provided.");
            }
            var result = (T) ctor.Invoke(parameters);
            return result;
        }</pre>]]></content:encoded>
      <snippet:downloads>1</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=d2385698-782b-43aa-b78b-93e6e7661e3b</guid>
      <title>String extension method that uses regular expressions to determine if the string matches to a given regex pattern. Allows you to specify RegExOptions</title>
      <link>/PreviewSnippet.aspx?SnippetID=d2385698-782b-43aa-b78b-93e6e7661e3b</link>
      <description>String extension method that uses regular expressions to determine if the string matches to a given regex pattern. Allows you to specify RegExOptions [C#]</description>
      <author>John Tolar</author>
      <pubDate>Tue, 23 Mar 2010 05:14:34 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=d2385698-782b-43aa-b78b-93e6e7661e3b#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>String extension method that uses regular expressions to determine if the string matches to a given regex pattern. Allows you to specify RegExOptions</dc:title>
      <dc:date>3/23/2010 5:14:34 AM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Uses regular expressions to determine if the string matches to a given regex pattern.
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="regexPattern">The regular expression pattern.</param>
        /// <param name="options">The regular expression options.</param>
        /// <returns>
        /// 	<c>true</c> if the value is matching to the specified pattern; otherwise, <c>false</c>.
        /// </returns>
        /// <example>
        /// <code>
        /// var s = "12345";
        /// var isMatching = s.IsMatchingTo(@"^\d+$");
        /// </code>
        /// </example>
        public static bool IsMatchingTo(this string value, string regexPattern, RegexOptions options)
        {
            return Regex.IsMatch(value, regexPattern, options);
        }</pre>]]></content:encoded>
      <snippet:downloads>1</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=48a46503-20ea-4f7c-a53d-94a7a1a0a3c1</guid>
      <title>Allows you to add string values to Enumerations using an Attribute. </title>
      <link>/PreviewSnippet.aspx?SnippetID=48a46503-20ea-4f7c-a53d-94a7a1a0a3c1</link>
      <description>Allows you to add string values to Enumerations using an Attribute.  [C#]</description>
      <author>John Tolar</author>
      <pubDate>Mon, 22 Mar 2010 14:38:07 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=48a46503-20ea-4f7c-a53d-94a7a1a0a3c1#comments</comments>
      <category>053f6cad-6b5e-4dd3-9c3d-f1b2979f7fcb</category>
      <dc:title>Allows you to add string values to Enumerations using an Attribute. </dc:title>
      <dc:date>3/22/2010 2:38:07 PM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/* EXAMPLE OF Implementation.
[Flags]
    public enum DaysOfTheWeek : short
    {
        [StringValue("Sunday")]
        Sunday = 1,
        [StringValue("Monday")]
        Monday = 2,
        [StringValue("Tuesday")]
        Tuesday = 4,
        [StringValue("Wednesday")]
        Wednesday = 8,
        [StringValue("Thursday")]
        Thursday = 16,
        [StringValue("Friday")]
        Friday = 32,
        [StringValue("Saturday")]
        Saturday = 64,
        [StringValue("AllDays")]
        AllDays = Saturday | Friday | Thursday | Wednesday | Tuesday | Monday | Sunday,
    }
*/
#region Class StringEnum
    /// <summary>
    /// Helper class for working with 'extended' enums using <see cref="StringValueAttribute"/> attributes.
    /// </summary>
    public class StringEnum
    {
        #region Instance implementation
        private static readonly Hashtable StringValues = new Hashtable();
        private readonly Type _enumType;
        /// <summary>
        /// Creates a new <see cref="StringEnum"/> instance.
        /// </summary>
        /// <param name="enumType">Enum type.</param>
        public StringEnum(Type enumType)
        {
            if (!enumType.IsEnum)
                throw new ArgumentException(String.Format("Supplied type must be an Enum.  Type was {0}", enumType));
            _enumType = enumType;
        }
        /// <summary>
        /// Gets the underlying enum type for this instance.
        /// </summary>
        /// <value></value>
        public Type EnumType
        {
            get { return _enumType; }
        }
        /// <summary>
        /// Gets the string value associated with the given enum value.
        /// </summary>
        /// <param name="valueName">Name of the enum value.</param>
        /// <returns>String Value</returns>
        public string GetStringValue(string valueName)
        {
            string stringValue = null;
            try
            {
                var enumType = (Enum) Enum.Parse(_enumType, valueName);
                stringValue = GetStringValue(enumType);
            }
            catch
            {
                //Swallow!
            } 
            return stringValue;
        }
        /// <summary>
        /// Gets the string values associated with the enum.
        /// </summary>
        /// <returns>String value array</returns>
        public Array GetStringValues()
        {
            var values = new ArrayList();
            //Look for our string value associated with fields in this enum
            foreach (FieldInfo fi in _enumType.GetFields())
            {
                //Check for our custom attribute
                var attrs = fi.GetCustomAttributes(typeof (StringValueAttribute), false) as StringValueAttribute[];
                if (attrs != null)
                    if (attrs.Length > 0)
                        values.Add(attrs[0].Value);
            }
            return values.ToArray();
        }
        /// <summary>
        /// Gets the values as a 'bindable' list datasource.
        /// </summary>
        /// <returns>IList for data binding</returns>
        public IList GetListValues()
        {
            Type underlyingType = Enum.GetUnderlyingType(_enumType);
            var values = new ArrayList();
            //Look for our string value associated with fields in this enum
            foreach (FieldInfo fi in _enumType.GetFields())
            {
                //Check for our custom attribute
                var attrs = fi.GetCustomAttributes(typeof (StringValueAttribute), false) as StringValueAttribute[];
                if (attrs != null)
                    if (attrs.Length > 0)
                        values.Add(new DictionaryEntry(Convert.ChangeType(Enum.Parse(_enumType, fi.Name), underlyingType),
                                                       attrs[0].Value));
            }
            return values;
        }
        /// <summary>
        /// Return the existence of the given string value within the enum.
        /// </summary>
        /// <param name="stringValue">String value.</param>
        /// <returns>Existence of the string value</returns>
        public bool IsStringDefined(string stringValue)
        {
            return Parse(_enumType, stringValue) != null;
        }
        /// <summary>
        /// Return the existence of the given string value within the enum.
        /// </summary>
        /// <param name="stringValue">String value.</param>
        /// <param name="ignoreCase">Denotes whether to conduct a case-insensitive match on the supplied string value</param>
        /// <returns>Existence of the string value</returns>
        public bool IsStringDefined(string stringValue, bool ignoreCase)
        {
            return Parse(_enumType, stringValue, ignoreCase) != null;
        }
        #endregion
        #region Static implementation
        /// <summary>
        /// Gets a string value for a particular enum value.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <returns>String Value associated via a <see cref="StringValueAttribute"/> attribute, or null if not found.</returns>
        public static string GetStringValue(Enum value)
        {
            string output = null;
            Type type = value.GetType();
            if (StringValues.ContainsKey(value))
                output = ((StringValueAttribute) StringValues[value]).Value;
            else
            {
                //Look for our 'StringValueAttribute' in the field's custom attributes
                FieldInfo fi = type.GetField(value.ToString());
                var attrs = fi.GetCustomAttributes(typeof (StringValueAttribute), false) as StringValueAttribute[];
                if (attrs != null)
                    if (attrs.Length > 0)
                    {
                        StringValues.Add(value, attrs[0]);
                        output = attrs[0].Value;
                    }
            }
            return output;
        }
        /// <summary>
        /// Parses the supplied enum and string value to find an associated enum value (case sensitive).
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="stringValue">String value.</param>
        /// <returns>Enum value associated with the string value, or null if not found.</returns>
        public static object Parse(Type type, string stringValue)
        {
            return Parse(type, stringValue, false);
        }
        /// <summary>
        /// Parses the supplied enum and string value to find an associated enum value.
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="stringValue">String value.</param>
        /// <param name="ignoreCase">Denotes whether to conduct a case-insensitive match on the supplied string value</param>
        /// <returns>Enum value associated with the string value, or null if not found.</returns>
        public static object Parse(Type type, string stringValue, bool ignoreCase)
        {
            object output = null;
            string enumStringValue = null;
            if (!type.IsEnum)
                throw new ArgumentException(String.Format("Supplied type must be an Enum.  Type was {0}", type));
            //Look for our string value associated with fields in this enum
            foreach (FieldInfo fi in type.GetFields())
            {
                //Check for our custom attribute
                var attrs = fi.GetCustomAttributes(typeof (StringValueAttribute), false) as StringValueAttribute[];
                if (attrs != null)
                    if (attrs.Length > 0)
                        enumStringValue = attrs[0].Value;
                //Check for equality then select actual enum value.
                if (string.Compare(enumStringValue, stringValue, ignoreCase) == 0)
                {
                    output = Enum.Parse(type, fi.Name);
                    break;
                }
            }
            return output;
        }
        /// <summary>
        /// Return the existence of the given string value within the enum.
        /// </summary>
        /// <param name="stringValue">String value.</param>
        /// <param name="enumType">Type of enum</param>
        /// <returns>Existence of the string value</returns>
        public static bool IsStringDefined(Type enumType, string stringValue)
        {
            return Parse(enumType, stringValue) != null;
        }
        /// <summary>
        /// Return the existence of the given string value within the enum.
        /// </summary>
        /// <param name="stringValue">String value.</param>
        /// <param name="enumType">Type of enum</param>
        /// <param name="ignoreCase">Denotes whether to conduct a case-insensitive match on the supplied string value</param>
        /// <returns>Existence of the string value</returns>
        public static bool IsStringDefined(Type enumType, string stringValue, bool ignoreCase)
        {
            return Parse(enumType, stringValue, ignoreCase) != null;
        }
        #endregion
    }
    #endregion
    #region Class StringValueAttribute
    /// <summary>
    /// Simple attribute class for storing String Values
    /// </summary>
    public class StringValueAttribute : Attribute
    {
        private readonly string _value;
        /// <summary>
        /// Creates a new <see cref="StringValueAttribute"/> instance.
        /// </summary>
        /// <param name="value">Value.</param>
        public StringValueAttribute(string value)
        {
            _value = value;
        }
        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <value></value>
        public string Value
        {
            get { return _value; }
        }
    }
    #endregion</pre>]]></content:encoded>
      <snippet:downloads>1</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=bfa9d2e4-6d4e-4824-9ee0-9a6be59a7abc</guid>
      <title>Set of Extension Methods to Check if Collection is Empty</title>
      <link>/PreviewSnippet.aspx?SnippetID=bfa9d2e4-6d4e-4824-9ee0-9a6be59a7abc</link>
      <description>Set of Extension Methods to Check if Collection is Empty [C#]</description>
      <author>John Tolar</author>
      <pubDate>Mon, 22 Mar 2010 14:05:22 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=bfa9d2e4-6d4e-4824-9ee0-9a6be59a7abc#comments</comments>
      <category>e5dc5661-427e-4d33-8be6-187bd2783223</category>
      <dc:title>Set of Extension Methods to Check if Collection is Empty</dc:title>
      <dc:date>3/22/2010 2:05:22 PM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Throws an <see cref="System.ArgumentNullException"/> 
        /// if the the value is null.
        /// </summary>
        /// <param name="value">The value to test.</param>
        /// <param name="message">The message to display if the value is null.</param>
        /// <param name="name">The name of the parameter being tested.</param>
        public static void ExceptionIfNullOrEmpty(this object value, string message, string name)
        {
            if (value == null)
                throw new ArgumentNullException(name, message);
        }
/// <summary>
    /// Extension Methods for Collection Objects
    /// </summary>
    public static class CollectionExtensions
    {
        /// <summary>
        /// Tests if the collection is empty.
        /// </summary>
        /// <param name="collection">The collection to test.</param>
        /// <returns>True if the collection is empty.</returns>
        public static bool IsEmpty(this ICollection collection)
        {
            collection.ExceptionIfNullOrEmpty(
                "The collection cannot be null.",
                "collection");
            return collection.Count == 0;
        }
        /// <summary>
        /// Tests if the collection is empty.
        /// </summary>
        /// <typeparam name="T">The type of the items in 
        /// the collection.</typeparam>
        /// <param name="collection">The collection to test.</param>
        /// <returns>True if the collection is empty.</returns>
        public static bool IsEmpty<T>(this ICollection<T> collection)
        {
            collection.ExceptionIfNullOrEmpty(
                "The collection cannot be null.",
                "collection");
            return collection.Count == 0;
        }
        /// <summary>
        /// Tests if the collection is empty.
        /// </summary>
        /// <param name="collection">The collection to test.</param>
        /// <returns>True if the collection is empty.</returns>
        public static bool IsEmpty(this IList collection)
        {
            collection.ExceptionIfNullOrEmpty(
                "The collection cannot be null.",
                "collection");
            return collection.Count == 0;
        }
        /// <summary>
        /// Tests if the collection is empty.
        /// </summary>
        /// <typeparam name="T">The type of the items in 
        /// the collection.</typeparam>
        /// <param name="collection">The collection to test.</param>
        /// <returns>True if the collection is empty.</returns>
        public static bool IsEmpty<T>(this IList<T> collection)
        {
            collection.ExceptionIfNullOrEmpty(
                "The collection cannot be null.",
                "collection");
            return collection.Count == 0;
        }
        /// <summary>
        /// Tests if the collection is empty.
        /// </summary>
        /// <param name="collection">The collection to test.</param>
        /// <returns>True if the collection is empty.</returns>
        public static bool IsEmpty(this IDictionary collection)
        {
            collection.ExceptionIfNullOrEmpty("The collection cannot be null.", "collection");
            return collection.Count == 0;
        }
        /// <summary>
        /// Tests if the IDictionary is empty.
        /// </summary>
        /// <typeparam name="K">The type of the key of 
        /// the IDictionary.</typeparam>
        /// <typeparam name="T">The type of the values
        /// of the IDictionary.</typeparam>
        /// <param name="collection">The collection to test.</param>
        /// <returns>True if the collection is empty.</returns>
        public static bool IsEmpty<K, T>(
            this IDictionary<K, T> collection)
        {
            collection.ExceptionIfNullOrEmpty(
                "The collection cannot be null.",
                "collection");
            return collection.Count == 0;
        }
        /// <summary>
        /// Tests if the 
        /// <see cref="System.Data.DataTable"/>
        /// is empty.
        /// </summary>
        /// <typeparam name="DR">The type of
        /// DataRow in the table.</typeparam>
        /// <param name="table">The table to test.</param>
        /// <returns>True if the table is empty.</returns>
        public static bool IsEmpty<DR>(
            this DataTable table)
            where DR : DataRow
        {
            table.ExceptionIfNullOrEmpty(
                "The table cannot be null.",
                "table");
            return table.Rows.Count == 0;
        }
        /// <summary>
        /// Tests if the array is empty.
        /// </summary>
        /// <param name="array">The array to test.</param>
        /// <returns>True if the array is empty.</returns>
        public static bool IsEmpty(this Array array)
        {
            array.ExceptionIfNullOrEmpty(
                "The array cannot be null.",
                "array");
            return array.Length == 0;
        }
    }</pre>]]></content:encoded>
      <snippet:downloads>0</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=df0e0024-9182-4ccf-a6c9-bc56a7e0f281</guid>
      <title>string extension method that converts the string to a byte-array using default/specified encoding.</title>
      <link>/PreviewSnippet.aspx?SnippetID=df0e0024-9182-4ccf-a6c9-bc56a7e0f281</link>
      <description>string extension method that converts the string to a byte-array using default/specified encoding. [C#]</description>
      <author>John Tolar</author>
      <pubDate>Tue, 23 Mar 2010 05:17:48 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=df0e0024-9182-4ccf-a6c9-bc56a7e0f281#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>string extension method that converts the string to a byte-array using default/specified encoding.</dc:title>
      <dc:date>3/23/2010 5:17:48 AM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>/// <summary>
        /// Converts the string to a byte-array using the default encoding
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <returns>The created byte array</returns>
        public static byte[] ToBytes(this string value)
        {
            return value.ToBytes(null);
        }
        /// <summary>
        /// Converts the string to a byte-array using the supplied encoding
        /// </summary>
        /// <param name="value">The input string.</param>
        /// <param name="encoding">The encoding to be used.</param>
        /// <returns>The created byte array</returns>
        /// <example><code>
        /// var value = "Hello World";
        /// var ansiBytes = value.ToBytes(Encoding.GetEncoding(1252)); // 1252 = ANSI
        /// var utf8Bytes = value.ToBytes(Encoding.UTF8);
        /// </code></example>
        public static byte[] ToBytes(this string value, Encoding encoding)
        {
            encoding = (encoding ?? Encoding.Default);
            return encoding.GetBytes(value);
        }
</pre>]]></content:encoded>
      <snippet:downloads>0</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
    <item>
      <guid>/PreviewSnippet.aspx?SnippetID=7f467d92-d79b-4a79-a916-eac8b5a0e83e</guid>
      <title>Convert Color Type to OLE Color value. Extension Method</title>
      <link>/PreviewSnippet.aspx?SnippetID=7f467d92-d79b-4a79-a916-eac8b5a0e83e</link>
      <description>Convert Color Type to OLE Color value. Extension Method [C#]</description>
      <author>John Tolar</author>
      <pubDate>Mon, 22 Mar 2010 14:24:48 GMT</pubDate>
      <comments>/PreviewSnippet.aspx?SnippetID=7f467d92-d79b-4a79-a916-eac8b5a0e83e#comments</comments>
      <category>b2432445-9f90-456a-985b-312f15214a9a</category>
      <dc:title>Convert Color Type to OLE Color value. Extension Method</dc:title>
      <dc:date>3/22/2010 2:24:48 PM</dc:date>
      <dc:creator>John Tolar</dc:creator>
      <content:encoded><![CDATA[<pre>public static int ToOleColor(this Color color)
        {
            return ColorTranslator.ToOle(color);
        }</pre>]]></content:encoded>
      <snippet:downloads>0</snippet:downloads>
      <snippet:rating>0</snippet:rating>
      <snippet:language>C#</snippet:language>
    </item>
  </channel>
</rss>