﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace UI
{
    /// <summary>
    /// This class acts as a wrapper for string value access in enumerations.
    /// </summary>
    public class StringEnum
    {
        /// <summary>
        /// This method return the string value associated with the given enum value
        /// </summary>
        /// <param name="value">given enum value</param>
        /// <returns>the string value associated with the given enum value</returns>
        public static string GetStringValue(Enum value)
        {
            string output = null;
            Type type = value.GetType();

           
                //Look for our 'StringValueAttribute' 
                //in the field's custom attributes
                FieldInfo fi = type.GetField(value.ToString());
                StringValueAttribute[] attrs =
                   fi.GetCustomAttributes(typeof(StringValueAttribute),
                                           false) as StringValueAttribute[];
                if (attrs.Length > 0)
                {
                    output = attrs[0].Value;
                }
            

            return output;
        }
    }
}
