Skip to content

Instantly share code, notes, and snippets.

@ilkerde
Created February 22, 2011 14:08
Show Gist options
  • Select an option

  • Save ilkerde/838709 to your computer and use it in GitHub Desktop.

Select an option

Save ilkerde/838709 to your computer and use it in GitHub Desktop.
I wonder whether introducing such an extension is considered a smell. For me it's most likely a smell.
using System;
namespace Is.This.A.Smell {
public static class EnumExtensions {
public static string AsString(this Enum e) {
return Enum.GetName(e.GetType(), e);
}
}
}
@ilkerde

ilkerde commented Feb 22, 2011

Copy link
Copy Markdown
Author

@forki: granted, makes life easier and hence is a good thing.
@shishkin: thanks. <- better? ;-)

@ilkerde

ilkerde commented Feb 22, 2011

Copy link
Copy Markdown
Author

@rseso: Very interesting approach. I'd never thought of decorating enum values with metadata.

@shishkin

Copy link
Copy Markdown

@ilker: Man, that's what I call continuous improvement! ;)

@dun3

dun3 commented Feb 23, 2011

Copy link
Copy Markdown

Most definitively a smell. But not the extension method itself, but the need for it and the use of Enum in a first place. This seems to no longer be a simple Enum and should most likely be replaced by a proper class(-hierarchy). We found that using an enum is often a premature optimization that will bite you in the end. Especially when decorating enums with attributes ... think very hard before going down that road.

Why did you use an enum in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment