/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections;
using System.Collections.Generic;
namespace Everest.Library.ExtensionMethod{
/// <summary>
///
/// </summary>
public class EnumItem
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private int _value;
public int Value
{
get { return _value; }
set { _value = value; }
}
/// <summary>
/// Initializes a new instance of the <see cref="EnumItem"/> class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public EnumItem(string name, int value)
{
_name = name;
_value = value;
}
}
public static class EnumHelper
{
/// <summary>
/// Gets the items.
/// </summary>
/// <param name="enumType">Type of the enum.</param>
/// <returns></returns>
public static IList<EnumItem> GetItems(Type enumType)
{
IList<EnumItem> list = new List<EnumItem>();
foreach (object value in Enum.GetValues(enumType))
{
string enumName = Enum.GetName(enumType, value);
EnumItem item = new EnumItem(enumName, (int)value);
list.Add(item);
}
return list;
}
}
}
|