Click here to Skip to main content
15,886,067 members
Home / Discussions / C#
   

C#

 
GeneralRe: Canonicalize a path (not a URL) Pin
Vikram A Punathambekar7-Jul-08 9:55
Vikram A Punathambekar7-Jul-08 9:55 
GeneralRe: Canonicalize a path (not a URL) Pin
James R. Twine7-Jul-08 10:52
James R. Twine7-Jul-08 10:52 
GeneralRe: Canonicalize a path (not a URL) Pin
Vikram A Punathambekar7-Jul-08 11:45
Vikram A Punathambekar7-Jul-08 11:45 
QuestionHi,How can I use Windows Media Player in Pocket PC 2003? Pin
xibeifeijian7-Jul-08 2:42
xibeifeijian7-Jul-08 2:42 
QuestionGetting a raw pointer to int from unmanaged C++ - Code Pin
Tomerland7-Jul-08 2:42
Tomerland7-Jul-08 2:42 
AnswerRe: Getting a raw pointer to int from unmanaged C++ - Code Pin
Luc Pattyn7-Jul-08 3:01
sitebuilderLuc Pattyn7-Jul-08 3:01 
GeneralRe: Getting a raw pointer to int from unmanaged C++ - Code Pin
Tomerland7-Jul-08 3:26
Tomerland7-Jul-08 3:26 
QuestionEnum and generics Pin
N a v a n e e t h7-Jul-08 2:22
N a v a n e e t h7-Jul-08 2:22 
I have a generic method which looks for a specific attribute and returns value of "Text" property. My attribute is named "DetailsAttribute". Here is my generic method

public static string GetDescription<EnumType>(EnumType enumType) {

    string description = string.Empty;

    Type type = enumType.GetType();
    if (type != null) {
       // Getting filed info
        FieldInfo info = type.GetField(enumType.ToString());
        if (info != null) {
            // getting the attributes
              DetailsAttribute[] attributes = info.GetCustomAttributes(typeof(DetailsAttribute), false)  as DetailsAttribute[];
              if (attributes != null && attributes.Length > 0)
                  description = attributes[0].Text;
        }
    }
    return description;
}
This works fine. But I am looking for applying a constraint to the generic parameter "enumType" which should allow only enum types. I am not able to write something like
public static string GetDescription<EnumType>(EnumType enumType) : where enumType : enum // error


How can I set such kind of restriction ? Also is there any better method than what I provided to retrieve attribute values from fields ?

any help would be appreciated.

All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia

How to use google | Ask smart questions

AnswerRe: Enum and generics Pin
leppie7-Jul-08 2:42
leppie7-Jul-08 2:42 
GeneralRe: Enum and generics Pin
N a v a n e e t h7-Jul-08 2:50
N a v a n e e t h7-Jul-08 2:50 
AnswerRe: Enum and generics Pin
xibeifeijian7-Jul-08 2:49
xibeifeijian7-Jul-08 2:49 
GeneralRe: Enum and generics Pin
N a v a n e e t h7-Jul-08 2:58
N a v a n e e t h7-Jul-08 2:58 
GeneralRe: Enum and generics Pin
xibeifeijian7-Jul-08 3:03
xibeifeijian7-Jul-08 3:03 
GeneralRe: Enum and generics Pin
N a v a n e e t h7-Jul-08 3:31
N a v a n e e t h7-Jul-08 3:31 
GeneralRe: Enum and generics Pin
leppie7-Jul-08 3:28
leppie7-Jul-08 3:28 
GeneralRe: Enum and generics Pin
N a v a n e e t h7-Jul-08 3:35
N a v a n e e t h7-Jul-08 3:35 
GeneralRe: Enum and generics Pin
leppie7-Jul-08 3:58
leppie7-Jul-08 3:58 
AnswerRe: Enum and generics Pin
PIEBALDconsult7-Jul-08 9:11
mvePIEBALDconsult7-Jul-08 9:11 
GeneralRe: Enum and generics Pin
xibeifeijian7-Jul-08 15:31
xibeifeijian7-Jul-08 15:31 
GeneralRe: Enum and generics Pin
N a v a n e e t h7-Jul-08 15:37
N a v a n e e t h7-Jul-08 15:37 
GeneralRe: Enum and generics [modified] Pin
PIEBALDconsult7-Jul-08 18:34
mvePIEBALDconsult7-Jul-08 18:34 
GeneralRe: Enum and generics Pin
N a v a n e e t h8-Jul-08 15:42
N a v a n e e t h8-Jul-08 15:42 
GeneralRe: Enum and generics Pin
Scott Dorman7-Jul-08 15:42
professionalScott Dorman7-Jul-08 15:42 
GeneralRe: Enum and generics Pin
PIEBALDconsult7-Jul-08 18:39
mvePIEBALDconsult7-Jul-08 18:39 
AnswerRe: Enum and generics Pin
Scott Dorman7-Jul-08 15:38
professionalScott Dorman7-Jul-08 15:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.