using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.Common.Extenions
{
    public static class EnumExtenions
    {
        public static DataTable EnumToDataTable(this Type enumType, string key, string val)
        {
            var names = Enum.GetNames(enumType);
            var values = Enum.GetValues(enumType);

            var table = new DataTable();
            table.Columns.Add(key, Type.GetType("System.Int32"));
            table.Columns.Add(val, Type.GetType("System.String"));
            table.Columns[key].Unique = true;
            for (int i = 0; i < values.Length; i++)
            {
                var dr = table.NewRow();
                dr[key] = (int)values.GetValue(i);
                dr[val] = names[i];
                table.Rows.Add(dr);
            }
            return table;
        }
    }
}

