|
using System;
namespace Frameworx
{
/// <summary>
/// Generic helper functions
/// </summary>
public class Tools
{
/// <summary>
/// Converts Integers to enum types
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">Enum int value</param>
/// <returns></returns>
/// <example>
/// Enums.ConvertToEnum<enum.type>([EnumAsInt]);
/// </example>
public static T ConvertToEnum<T>(int value)
{
return (T)Enum.ToObject(typeof(T), value);
}
/// <summary>
/// Converts String to enum types
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">Enum string value</param>
/// <returns></returns>
/// <example>
/// Enums.ConvertToEnum<enum.type>([EnumAsString]);
/// </example>
public static T ConvertToEnum<T>(string value)
{
return (T)Enum.Parse(typeof(T), value, true);
}
}
}
|
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.
Darren James is technical director at Frame Digital, the online arm of scottish advertising agency Frame.
He spends his working day developing content managed solutions for a wide range of clients, and trying to make it look easy. (It doesn't always work)
When not immersed in code, he has an unhealthly obsession with online games, and tries to travel as much as possible.
His current ambition is to find some time to update his
company website, in the meantime, you can find
more articles on his blog.