반응형
public enum animal
{
public static class EnumHelper
{
심재운님 티스토리로 가야함
출처 : 심재운님 티스토리
{
[Description("똥꼬양이")]
cat = 1,
[Description(똥꾸 멍멍멍멍멍!!~)]
dog = 2,
[Description(똥 뙈 지)]
pig = 3,
[Description(똥꾸 멍멍멍멍멍!!~)]
dog = 2,
[Description(똥 뙈 지)]
pig = 3,
}
public static class EnumHelper
{
public static string GetDescription(Enum e)
{
{
Type type = e.GetType();
MemberInfo[] memInfo = type.GetMember(e.ToString());
if(memInfo != null && memInfo.Length > 0)
{
if(memInfo != null && memInfo.Length > 0)
{
object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
if(attrs != null & attrs.Length > 0)
{
if(attrs != null & attrs.Length > 0)
{
return((DescriptionAttribute)attrs[0]).Description;
}
}
return e.ToString();
return e.ToString();
}
}
using System.ComponentModel; //해줘야지
using System.Reflection;
기존 enum.Parser로 하던 방법에서는 띄어쓰기 및 한글로 가져오기가 힘들었지비... (한글로 코딩해노면 쌍싸다구 얻어맞음)
그러니께리 리플렉션 이용한 요 방법이 지금은 좋을듯...
좀 더 자세한 내용은using System.ComponentModel; //해줘야지
using System.Reflection;
기존 enum.Parser로 하던 방법에서는 띄어쓰기 및 한글로 가져오기가 힘들었지비... (한글로 코딩해노면 쌍싸다구 얻어맞음)
그러니께리 리플렉션 이용한 요 방법이 지금은 좋을듯...
심재운님 티스토리로 가야함
출처 : 심재운님 티스토리
반응형
'프로그래밍' 카테고리의 다른 글
Visual Studio 2010 사용자 환경 초기화 (0) | 2011.03.10 |
---|---|
[C#] ListView VirtualMode 예제 (0) | 2011.02.25 |
[C#] DataGridView, ListView 속도 향상법 (0) | 2011.02.22 |
[C#] Operator Overloading in C# (0) | 2011.02.08 |
[C#] 초간단 성능테스트 하기 (0) | 2011.01.20 |
댓글